Towards GNU/MINIX - libstdc++

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

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 supporting POSIX pthread. You need to define symbol _MTHREADIFY_PTHREADS to enable the support. This is needed by GCC. Internally, GCC uses gthread which is a wrapper around pthread.
  • libtool allows you to create objects and libraries in a cross-platform way. It's a bash shell script.
  • -std=c++0x compiler flag refers to c++11 standard.
  • Use -nostdinc (or -nostdinc++) and -nostdlib to avoid including standard includes and libraries respectively.
  • __stdcall is Windows API and is not supported on *nix.
  • Following error is typically a mismatch between the internal type of size_t and the one defined in the header file.
 The definition of std::initializer_list does not contain the expected constructor
 
  • Clang uses __config whereas GCC uses bits/c++config.h for C++ configuration.
  • Clang uses featuretest.h whereas GCC uses features.h for some useful C macros.
  • Currently, the GCC generic model only supports the "C" locale. See http://gcc.gnu.org/ml/libstdc++/2003-02/msg00345.html. This may cause failure on std::cout since the locale may be something other than "C" locale.
  • You must specify file type before - while taking source from stdin. Otherwise a filetype will be assumed eg. C which might not be what you want.
$ echo "#include <bits/c++config.h> _GLIBCXX_HAVE_FENV_H" | i686-elf-g++ -E -v -x c++ -
 

 

Code

 

References



 


 

 

Comments

Popular posts from this blog

GNU Emacs as a Comic Book Reader

HTML Renderer (Emacs)

Mozilla Readability in GNU Emacs