I have some basic knowledge about compiling C but need to get a couple of generic cross-compilation questions answered. In my case, I am trying to cross-compile a program on my Fedora Linux box that is going to be run on an ARM single board computer.
My first question is about headers. I have downloaded the arm Linux tools package and it contains headers files such as stdio.h in an include directory. Am I supposed to use this "target" include directory as opposed to my system include directories when I am cross-compiling? Or is it OK to point to my system's include dirs such as /usr/include? (These header files seem to be different when I diff them.)
What happens if a header file does not exist. In my case, I am also planning to utilize the cURL library on the ARM board. Can I simply point to the include directory present in the curl source package that I downloaded without worrying about the target architecture? If yes, does this mean my first question is irrelevant?
Let's say I want to statically link to a library. Does this static library need to be compiled for the target ARM platform before this happens? Or can I use the static libraries installed on my system directly (hoping that the cross compilation process takes care of business)?
If I decide to dynamically link to a library, the only requirement would be that the target system has this library compiled for ARM and installed in one of the LD_LIBRARY_PATH directories on the ARM board, am I correct?
Thanks for the help.
To cross-compile is to build on one platform a binary that will run on another platform. When speaking of cross-compilation, it is important to distinguish between the build platform on which the compilation is performed, and the host platform on which the resulting executable is expected to run.
A cross compiler is a compiler capable of creating executable code for a platform other than the one on which the compiler is running. For example, a compiler that runs on a PC but generates code that runs on an Android smartphone is a cross compiler.
"building a cross-compiler is significantly harder than building a compiler that targets the platform it runs on." The problem exists due to the way libraries are built and accessed. In the normal situation all the libraries are located in a specific spot, and are used by all apps on that system.
Explanation: GCC, a free software collection of compilers, also can be used as cross compile. It supports many languages and platforms.
fakeroot
can be helpful for dirty build systems.Any library you intend on using, including the libc, must be built for the target platform before you can link against it. Use the target headers instead of the host headers for building so that you're assured of using the correct API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With