Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

linux

gcc

linker

ld

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 file 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?

like image 430
Christoph Wurm Avatar asked Nov 06 '22 01:11

Christoph Wurm


2 Answers

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

like image 178
mduvall Avatar answered Nov 10 '22 19:11

mduvall


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 !

like image 24
morandg Avatar answered Nov 10 '22 19:11

morandg