如何在不同目录中链接到没有lib *前缀的共享库? [英] How to link to a shared library without lib* prefix in a different directory?
问题描述
我必须将我的代码链接到没有lib前缀的共享库。 (比如foo.so)第一个问题是-l选项没有找到该文件。所以我试图直接将这个文件包含到最后一个编译内容中:
gcc a ao /PATH/TO/FOO/foo.so
但是在这种情况下,a很难链接到foo.so作为绝对路径,如ldd a所示:
/ PATH / TO / FOO / foo.so
在最终部署中,两个文件最终都会位于同一个文件夹中,因此这应该是正常链接,而不是绝对路径。我怎样才能做到这一点?
-Wl,-rpath ,. - >使用当前目录搜索lib文件。 (即使没有在编译中找到,在运行时就ok了)
而不是-llibrary - >使用library.so。
这似乎工作正常。希望任何人都认为这很有用。
I have to link my code to a shared library without the lib prefix. (say, foo.so) The first problem is -l option does not find the file. So I tried directly including this file to the last compilation like this:
gcc a a.o /PATH/TO/FOO/foo.so
But in this case, a is hard linked to foo.so as an absolute path as seen in "ldd a":
/PATH/TO/FOO/foo.so
In the final deployment both files would end up being in the same folder, so this should be normal link, not the absolute path. How can I do this?
-Wl,-rpath,. --> to use current directory for searching lib files. (even if not found in compilation, ok at run-time) instead of -llibrary --> use library.so.
This seems to work correctly. Hope anyone finds this useful.
这篇关于如何在不同目录中链接到没有lib *前缀的共享库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!