[英]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.