Linking a shared library
Sat Jun 2 05:54:00 GMT 2018
On Fri, 1 Jun 2018, Edward Diener wrote:
> An executable I am creating needs to link and run with a shared library
> called, let's say, 'libmyshare.so' in a relative directory called, let's say
> Does using the -L option while compiling the source files to object files add
> the relative directory 'mylibs/lib' to the library search path for shared
> libraries when linking ?
No. Since -L tells -l where to look, why would you want to separate them
into 2 separate commands? Did some documentation recommend that somewhere?
clang even gives you a warning if you pass -L to a compile (-c) command.
> Do I specify the shared library to the linker as '-lmyshare' when linking or
> do I rather specify the shared library simply as 'libmyshare.so' when linking
-lmyshare (or you can pass /full/path/to/libmyshare.so and omit the -L
> I have tried using '-Lmylibs/lib' when compiling and '-lmyshare' when linking
> but the linker fails with the message:
> /usr/bin/ld: cannot find -lmyshare
> so I am doing something wrong and do not know what it is.
(your next question will likely be how to tell where to find the library
More information about the Gcc-help