First of all, you need to know which libraries you depend on. ldd can help you, but don’t be too happy. Some programs use dynamically loaded libraries. Whether these dynamically loaded libraries depend on other libraries will not pass ldd This static analysis tool knows that you need to find these dynamically loaded libraries and call ldd repeatedly.
But knowing the dependencies does not solve your problem. I think you want to be able to compile an executable file without dependencies and run it directly on other machines. This requires recompiling the program source code using 静态链接. At the same time, the dependent library also needs to provide an archive version of the library (usually .a) instead of .so. Many dependent libraries do not install the .a version of the library by default during installation. Even for some libraries, even if you compile them from source code, the archive version of the library cannot be compiled by default.
One additional point: If you try to statically compile glibc into an executable file, please try not to do so. glibc is a basic library included in almost all Linux distribution systems. It generally does not need to be statically linked into the program, and glibc is backward compatible. Therefore, you only need to compile it under a relatively low version of glibc, and the program can be run on the Linux system. Better portability between . If you use C++, then stdlib may be something you also want to consider. Trying to make glibc static can cause some mysterious problems.
You can only package the dynamic library. Compilation requires the use of static linking when linking the source code. . When packaging, you should also pay attention to the version of the underlying library (such as glibc). If the machine environment is the same, there will be no problem. Also, when running, you need to manually set LD_LIBRARY_PATH to start your program. . Same as upstairs + upstairs upstairs lddYou can view the direction of the dynamic library link used by elf the program. .
First of all, you need to know which libraries you depend on.
ldd
can help you, but don’t be too happy. Some programs use dynamically loaded libraries. Whether these dynamically loaded libraries depend on other libraries will not passldd
This static analysis tool knows that you need to find these dynamically loaded libraries and callldd
repeatedly.But knowing the dependencies does not solve your problem. I think you want to be able to compile an executable file without dependencies and run it directly on other machines. This requires recompiling the program source code using
静态链接
. At the same time, the dependent library also needs to provide an archive version of the library (usually.a
) instead of.so
. Many dependent libraries do not install the.a
version of the library by default during installation. Even for some libraries, even if you compile them from source code, the archive version of the library cannot be compiled by default.One additional point: If you try to statically compile glibc into an executable file, please try not to do so. glibc is a basic library included in almost all Linux distribution systems. It generally does not need to be statically linked into the program, and glibc is backward compatible. Therefore, you only need to compile it under a relatively low version of glibc, and the program can be run on the Linux system. Better portability between . If you use C++, then stdlib may be something you also want to consider. Trying to make glibc static can cause some mysterious problems.
The ldd command under Linux checks the libraries that the executable program depends on
You can only package the dynamic library. Compilation requires the use of static linking when linking the source code. .
When packaging, you should also pay attention to the version of the underlying library (such as
glibc
). If the machine environment is the same, there will be no problem. Also, when running, you need to manually setLD_LIBRARY_PATH
to start your program. .Same as upstairs + upstairs upstairs
ldd
You can view the direction of the dynamic library link used byelf
the program. .