0

I want to compile a C file with gcc, to embedded arm that is running Gnu/Linux .

How can I known which function/header files that I need to compile statically, and which dynamically?(I don't want to compile all of the headers file statically )

Is there any command that I can use?

For example I include stdio.h to use printf, is there any way to know if I must compile it statically?

  • It's called 'linking'. It depends on the library and which command is used at the time of linking (after compiling). – Biswapriyo Apr 7 at 4:49
  • @Biswapriyo For example I include stdio.h to use printf , is there any way to know if I must compile it statically ? – Image base Apr 7 at 4:57
1

You'll need to know which dynamic libraries will be available on your target system and which are not.

For example, on my system stdio.h is one of the include files of package libc6-dev (Debian package naming conventions), and the corresponding dynamic library is libc.so.6 which is a symbolic link to libc-2.24.so. This is the GNU C Library, which is the basic building block of nearly all programs, so it would be quite unusual for your ARM system to not have it (or some equivalent of it) available as a dynamic library: since it is so universally used and fairly large, having it as a dynamic library makes very much sense.

(Also, GNU C Library itself uses dynamic linking for features like configurable name resolution functions: /etc/nsswitch.conf tells the C library which libnss_*.so libraries to load at run-time, so linking the GNU C Library fully statically to your program would be exceptionally tricky.)

If your embedded ARM system does not have a specific lib*.so file for a specific library installed on it, and you still wish to use that library in your program, then you must link that library statically. And to do that in a cross-compilation situation, you must have the corresponding ARM version of the lib*.a file of that library on the system you're cross-compiling your program.

Although a library's header files (*.h) might well be the same for all architectures the library is compilable in, the *.so and *.a files won't be: since the *.so and *.a files both contain executable code, they are specific for each processor architecture. So if you are cross-compiling for ARM on a x86_64 system, having the x86_64 version of some library's lib*.a file available won't allow you to cross-compile an ARM program using that library statically compiled: you will need the ARM lib*.a for that library.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.