C ++:如何链接到libA.so而不是libA-X.Y.Z.so [英] C++ : how to link against libA.so and not libA-X.Y.Z.so
问题描述
我有一个图书馆A,我开发。当我在机器上部署它时,相应的 libA.so 和 libA-X.Y.Z.so 放在/ usr / lib(X.Y.Z是版本号)。
I have a library A, that I develop. When I deploy it on a machine, the corresponding libA.so and libA-X.Y.Z.so are put in /usr/lib (X.Y.Z being the version number).
现在我开发一个库B,它使用A.当我链接B,我使用标志-lA。然后 ldd libB.so 给我:
Now I develop a library B, which uses A. When I link B, I use the flag -lA. Then "ldd libB.so" gives me :
(...)
libA-X.Y.Z.so => /usr/lib/libA-X.Y.Z.so
(...)
当我发布一个新版本的A(XYZZ),我也必须发布一个新版本的B.否则,有人安装最新的A将无法安装B,将寻找的版本XYZ的
My problem is that when I release a new version of A (X.Y.ZZ), I also have to release a new version of B. Otherwise, someone installing the latest A won't be able to install B which will be looking for the version X.Y.Z which doesn't exist.
如何解决这个问题?我如何告诉B查找libA.so而不是libA-X.Y.Z.so?还是这样做是错误的?甚至不安全?
How do I solve this problem ? How can I tell B to look for libA.so and not libA-X.Y.Z.so ? Or is it wrong to do so ? even unsafe ?
更新1 :库A(我从其他人继承而来)使用自动工具。
Update 1 : library A (that I inherited from someone else) uses autotools.
更新2 :构建库A时,可以看到: - wl,-soname -Wl,libA-0.6 .so。如果我理解正确,这意味着我们强制soname是 libA-0.6.1.so 。是对的吗 ?现在我的问题是,我没有线索如何修改这个行为在一个使用autotools的项目。我googled了一会儿,但是找不到任何有用的信息。我应该修改configure.in还是Makefile.am?
Update 2 : when I build library A, I can see : "-Wl,-soname -Wl,libA-0.6.1.so". If I understand properly that means that we are forcing the soname to be libA-0.6.1.so. Is that right ? Now my problem is that I have no clue how to modify this behaviour in a project which uses autotools. I googled for a while but can't find any useful information. Should I modify configure.in or a Makefile.am ?
推荐答案
在创建libA.so时,将-soname选项传递给链接器(如果通过gcc链接, ,-soname)。然后,当B链接时,链接器通过其soname而不是通过其文件名来引用A.在目标系统上,确保您具有从soname到真实文件的链接。请参阅
When you create libA.so, pass the -soname option to the linker (if you linking through gcc, use -Wl,-soname). Then, when B gets linked, the linker refers to A through its soname, not through its filename. On the target system, make sure you have a link from the soname to the real file. See
http://www.linux.org/docs/ldp/howto/Program-Library-HOWTO/shared-libraries.html
这篇关于C ++:如何链接到libA.so而不是libA-X.Y.Z.so的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!