Posts

Showing posts with the label cross-compile

Towards GNU/MINIX - libstdc++

Image
Cross-compiled C++ program running on Minix   To compile a C++ program, we need C++ standard library. While Clang libc++.so comes with Minix distribution, GCC version of libstdc++.so has to be cross-compiled . Interestingly, while GNU C library Glibc is a separate project, libstdc++ is part of the GCC project. In other words, you can use a different C library (like musl or ulibc) with GCC if you want. Lessons Learnt Clang uses inline namespaces by default whereas GCC does not. anand@PureBook:~/work/minix/usr/lib$ nm -s libstdc++.so | c++filt | grep cout 00328a20 b __gnu_internal::buf_cout_sync 00329080 b __gnu_internal::buf_wcout_sync 00328ae0 b __gnu_internal::buf_cout 00329140 b __gnu_internal::buf_wcout 003285c0 B std::cout 00328840 B std::wcout anand@PureBook:~/work/minix/usr/lib$ nm -s libc++.so | c++filt | grep cout 000c2b00 B std::__1::cout 000c2c54 B std::__1::wcout   You can use objcopy to alter symbol name in an object file or library. mthread.h has provisions for...

Towards GNU/MINIX - Cross-compiler

Image
Cross-compiled executable running on Minix   In this post, we will cross compile a binary on Linux using GNU tools and run the same in Minix with a minimal setup. Build a generic cross-compiler You can build a generic ELF compiler for x86 platform following the instructions here .   Copy C runtime files from the distribution CD. $PREFIX and $TARGET are variables set in previous step. $ sudo kpartx -a myos.iso $ sudo mount /dev/mapper/loop0p3 -t minix /mnt $ mkdir usr $ cp /mnt/lib usr $ cp /mnt/include usr $ sudo umount /mnt $ ln -s $PWD/usr $PREFIX/$TARGET/   Create hello.c  #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) {  printf("Hello\n");  return 0; }   Compile and link hello.c . Use -static for static linking and -dynamic-linker /usr/libexec/ld.elf_so (use appropriate ld path) for dynamic linking. $ i686-elf-gcc -o hello.o -c hello.c $ i686-elf-ld -static -m elf_i386 -o hello -L./usr/lib ./usr/lib/crt0.o...