Pointing to correct headers when cross compiling


This is a very small basic question that I have about cross compiling.

Let’s say I have an application which requires standard Linux headers like #include <sys/socket.h>.

But if I want to compile this application to a BBB with the build machine as Ubuntu, shouldn’t I point to the correct Kernel headers when building? I am not about Kernel modules, but about simple C applications.

Thank you.


The Linux headers are pretty much standard across Linux.
So, no, you don’t normally need to point at special header files.

The differences in the target machine architectures are mostly dealt
with in the cross-compiler and glibc (shared object) library modules that come with the
compiler. It is best to use a compiler that is using the same version
of the glibc libraries as the target machine, so that they can dynamically
link at run time. They are supposed to be somewhat backwards compatible,
but not always.

For instance, Debian 7 is using glibc version 2.13, which is many years old.
The current gcc cross compiler for Linux-arm uses 2.19.
The Angstrom distribution for BBB used 2.15
Fortunately, Debian 8 (jessie) uses 2.19, so should work well with the gcc cross compiler.

If you use a function that was added in a later version in your
program, but is not in the target glibc library, then the program will compile,
but won’t dynamically link at run time, and the target computer gives you some
totally misleading error messages when you try to start your program.

You can sometimes get around this by using the -static option with your
compiler and linker, which compiles the library in the cross-compiler host
into the executable, so the necessary library functions are there, but your
executable will be many times larger with statically linked libraries than
with the dynamically linked libraries.

To check your version of glibc libraries, run:

ldd --version

— Graham