views:

82

answers:

2

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

Now, I am compiling app.bin which is using libshared.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?

+1  A: 

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
R Samuel Klatchko
+2  A: 

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

nos