LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   strange linking error -- can not find shared library (https://www.linuxquestions.org/questions/programming-9/strange-linking-error-can-not-find-shared-library-462560/)

George2 07-10-2006 05:29 AM

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()
{
        return 10;
}

goo.h

Code:

int goo_export();
foo.c

Code:

#include "goo.h"

int main()
{
        goo_export();
}

Error messages,

[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

taylor_venable 07-10-2006 11:24 AM

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.