开发者

Why does the GNU linker not find a shared object with -l<library>?

I'm getting an error when trying to link an object file:

$ g++ -o intro intro.o -L -Wl,-rpath-link  -lnotes -lm -lnsl -lpthread -lc -lresolv -ldl
/usr/bin/ld: cannot find -lnotes
collect2: ld returned 1 exit status

However, the library seems to be there (in fact, I put it there by including /opt/ibm/lotus/notes in a fi开发者_如何学Gole in /etc/ld.so.conf.d/ and running ldconfig):

$ ldconfig --print-cache | grep libnotes                                                      
361:    libnoteswc.so (libc6) => /opt/ibm/lotus/notes/libnoteswc.so
362:    libnotes.so (libc6) => /opt/ibm/lotus/notes/libnotes.so

Why does the linking fail and how can I bring the linker to use these shared objects?


GCC does not specify a runpath so that the dynamic linker can find dynamic libraries at runtime...Yet another option, that works on a few platforms, is to hard-code the full pathname of the library into its soname. This can only be accomplished by modifying the appropriate .ml file within libstdc++/config (and also libg++/config, if you are building libg++), so that $(libdir)/ appears just before the library name in -soname or -h options.

http://gcc.gnu.org/faq.html#rpath


Try with the -L flag for ld. An example of one of my Makefile :

CFLAGS=-c -Wall -O2 \
       -I../libs/libs-x86/include
LDFLAGS=-lupnp \
        -L ../libs/libs-x86/lib

I think libraries described in "/etc/ld.so.conf.d/" are for runtime only ... Hope this helps !

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜