2013-05-31 93 views
1

库我不能用我的。所以LD看不到我刚刚建立

[0] [[email protected] segfaulty]$ cat Makefile 
all: ishy_crashy.so main.c 
    gcc -L. -lishy_crashy -o crashy main.c 

ishy_crashy.so: libby.h libby.c 
    gcc -fPIC -shared -Wl,-soname,ishy_crashy -o ishy_crashy.so libby.c 
[0] [[email protected] segfaulty]$ make 
gcc -fPIC -shared -Wl,-soname,ishy_crashy -o ishy_crashy.so libby.c 
gcc -L. -lishy_crashy -o crashy main.c 
/usr/bin/ld: cannot find -lishy_crashy 
collect2: error: ld returned 1 exit status 
make: *** [all] Error 1 
[2] [[email protected] segfaulty]$ file ishy_crashy.so 
ishy_crashy.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=0x0bcbdf5d7d1b88222ee057c014c906cd9fdd859d, not stripped 
[0] [[email protected] segfaulty]$ echo $LD_LIBRARY_PATH 

[0] [[email protected] segfaulty]$ export LD_LIBRARY_PATH=.:`pwd`:/lib:/usr/lib:/usr/local/lib 
[0] [[email protected] segfaulty]$ make 
gcc -L. -lishy_crashy -o crashy main.c 
/usr/bin/ld: cannot find -lishy_crashy 
collect2: error: ld returned 1 exit status 
make: *** [all] Error 1 
[2] [[email protected] segfaulty]$ ls 
ishy_crashy.so libby.c libby.h main.c Makefile 
[0] [[email protected] segfaulty]$ echo $LD_LIBRARY_PATH 
.:/tmp/segfaulty:/lib:/usr/lib:/usr/local/lib 

What'm我缺少的链接?

回答

1

参数-lishy_crashy表示寻找libishy_crashy.solibishy_crashy.a。您在库文件名中缺少lib前缀。

1

因为库的命名约定是使用前缀lib。标准工具知道,所以-lxyz寻找一个名为libxyz.so/libxyz.a的库。