strange linking error -- can not find shared library
Hello everyone,
I am meeting with a strange linking error when linking with a shared library on Linux platform. I use goo.c to generate libgoo.so, then write an application foo.c and link it with libgoo.so. The error occurs when linking with libgoo.so. The strange point is that, the LD_LIBRARY_PATH is not working, but -L option to gcc works -- I think they should be the same, but in my case below, it seems only -L works. Here are the source codes, goo.c Code:
int goo_export() Code:
int goo_export(); Code:
#include "goo.h" [root@localhost shared_goo]# gcc -shared goo.c -o libgoo.so [root@localhost shared_goo]# export LD_LIBRARY_PATH=. [root@localhost shared_goo]# gcc -I. -lgoo foo.c /usr/bin/ld: cannot find -lgoo collect2: ld returned 1 exit status [root@localhost shared_goo]# gcc -I. -L. -lgoo foo.c thanks in advance, George |
I believe LD_LIBRARY_PATH is for use at execution time, not at linking time. (To determine when to use LD_LIBRARY_PATH, call ldd on the binary. If it can't find a shared lib, you have to set LD_LIBRARY_PATH to tell the kernel where to look.)
|
All times are GMT -5. The time now is 06:33 PM. |