【问题标题】:ld can't see a library I just builtld 看不到我刚建的库
【发布时间】:2013-05-31 15:13:16
【问题描述】:

我无法链接到我的 .so

[0] [ishpeck@yoshimitsu 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] [ishpeck@yoshimitsu 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] [ishpeck@yoshimitsu 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] [ishpeck@yoshimitsu segfaulty]$ echo $LD_LIBRARY_PATH

[0] [ishpeck@yoshimitsu segfaulty]$ export LD_LIBRARY_PATH=.:`pwd`:/lib:/usr/lib:/usr/local/lib
[0] [ishpeck@yoshimitsu 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] [ishpeck@yoshimitsu segfaulty]$ ls
ishy_crashy.so  libby.c  libby.h  main.c  Makefile
[0] [ishpeck@yoshimitsu segfaulty]$ echo $LD_LIBRARY_PATH
.:/tmp/segfaulty:/lib:/usr/lib:/usr/local/lib

我错过了什么?

【问题讨论】:

    标签: gcc linker shared-libraries ld


    【解决方案1】:

    参数-lishy_crashy 表示查找libishy_crashy.solibishy_crashy.a。您缺少库文件名上的 lib 前缀。

    【讨论】:

      【解决方案2】:

      因为库的命名约定是使用前缀lib。标准工具理解这一点,因此-lxyz 会查找名为libxyz.so/libxyz.a 的库。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-05-03
        • 2015-02-05
        • 2014-12-13
        • 2016-03-29
        • 2021-10-24
        • 2017-03-31
        • 1970-01-01
        • 2011-09-26
        相关资源
        最近更新 更多