c++ - linux如何把一个二进制可执行文件依赖的库找出来并编译成另一个可执行文件呢?
高洛峰
高洛峰 2017-04-17 15:17:02
0
3
714

这样把文件拷贝到其他地方就可以使用了

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(3)
大家讲道理

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.

大家讲道理

The ldd command under Linux checks the libraries that the executable program depends on

ldd 可执行文件名
大家讲道理

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. .

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template