简体   繁体   English

Linux上的C ++,确认库中的代码未静态链接到生成的可执行文件中

[英]C++ on Linux, confirm code from library is not being statically linked into resulting executable

C++ on Linux, I'm building an executable which previously linked against a static library (.a), I've updated the build so that it now links against this library dynamically (.so). 在Linux上的C ++中,我正在构建一个以前链接到静态库(.a)的可执行文件,我已经更新了构建,以便现在可以动态链接到该库(.so)。 I want to confirm that the code from this library is no longer statically being linked into the executable. 我想确认该库中的代码不再静态链接到可执行文件中。 I was hoping to be able to confirm this by comparing the nm output from the statically linked vs dynamically linked executable but there are so many differences between these that it would be a manual effort to confirm this way...wondering if there is a better way that anyone can recommend? 我希望能够通过比较静态链接的可执行文件与动态链接的可执行文件的nm输出来确认这一点,但是它们之间有太多差异,因此需要人工来确认这种方式...想知道是否有更好的方法任何人都可以推荐的方式?

There's the nm command. nm命令。 It lists the modules functions. 它列出了模块功能。 Runs the nm command and grep a function you know is in the lib/so. 运行nm命令并grep lib / so中已知的功能。 If it's dynamically linked (so library) you'll see a "U" attribute to it. 如果它是动态链接的(so库),您将看到一个“ U”属性。

Example (perl path is made up): 示例(组成perl路径):

nm /bin/perl | grep fprintf

Output: 输出:

U fprintf@@GLIBC_2.2.5

Note: ldd is useful for knowing if you depend on an SO. 注意: ldd对于了解您是否依赖SO是很有用的。 But this SO can be a dependency of another SO. 但是此SO可能是另一个SO的依赖项。 In some cases you could get both static and dynamic versions of the library linked to your binary causing horrible memory issues (usually seen as double free error). 在某些情况下,您可能同时将静态版本和动态版本的库链接到二进制文件,从而导致可怕的内存问题(通常被视为double free错误)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从python调用静态链接的C库在Windows上永久挂起,但在OSX或linux上永远挂起 - Calling statically linked C library from python hangs forever on windows but not OSX or linux 在 C/C++ 中,如何确定库是否为静态链接 - In C/C++, how do I determine if a library is statically linked or not GDB 可以使用静态链接库重新加载可执行文件吗? - Can GDB reload executable with a statically linked library? 当一个C库静态链接时,整个库是否会被添加到可执行文件中? - When a C library is statically linked does the whole library get added to the executable? 从可执行文件中提取静态链接库 - Extract statically linked libraries from an executable 为什么可执行文件小于与应用程序项目静态链接的库? - why executable is smaller than the library which is statically linked with application project? C / C ++:静态链接库和目标文件有什么区别? - C/C++: What is the difference between a statically-linked library and an object file? 如何在Linux(Ubuntu)中使用FreeImage库静态编译C / C ++应用程序? - How to compile C/C++ application statically with FreeImage library in Linux (Ubuntu)? 数学库是静态链接的吗? - Is the math library linked statically? 制作一个静态链接的库 - Make a library that is statically linked
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM