开发者

How to resolve shared library linking during compilation( GCC )?

I have built libshared.so with is dependent on libshared_dependent.so

Now, I am compiling app.bin which is using libsh开发者_如何学运维ared.so, Now at compile time gcc wants me to specify -lshared_dependent other wise it gives error that some symbols not found.

Is there any way by which, At compile time I don't need to specify -lshared_dependent, I want that just specifying -lshared works?


You just need to link libshared.so to libshared_dependent.so when you are producing libshared.so.

gcc -shared -o libshared.so -lshared_dependant file1.o file2.o 

This way, when you link your app to libshared.so it'll also link to whatever libshared.so depends on


You shouldn't need to have app.bin link with libshared_dependent.so.

That said, the linker will want to verify the symbols in libshared.so can be found so it will need to locate libshared_dependent.so in order to do that. If libshared_dependent.so is in a different directory then libshared.so, you will want to specify the path to libshared_dependent.so using the linker option -rpath-link.

Because -rpath-link is a linker option, you will need to tell gcc to pass it through to the linker:

gcc -Wl,-rpath-link,/directory-that-libshared_dependent-is-in
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜