找不到/ usr / local / lib中的共享库

时间:2011-05-03 17:48:35

标签: c linux gcc debian

我不明白。我通常将第三方软件安装到 / usr / local 中,因此库安装在/ usr / local / lib中,并且从未遇到过链接到这些库的问题。但现在它突然不再起作用了:

$ gcc -lkaytils -o test test.c
/usr/bin/ld.gold.real: error: cannot find -lkaytils
/usr/bin/ld.gold.real: /tmp/ccXwCkYk.o: in function main:test.c(.text+0x15):
error: undefined reference to 'strCreate'
collect2: ld returned 1 exit status

当我添加参数-L/usr/local/lib而不是它可以工作但我以前从未使用过它。找到 / usr / local / include 中的头文件而不添加-I/usr/local/include

我正在使用Debian GNU / Linux 6(Squeeze),它在 /etc/ld.so.conf.d/libc中有 / usr / local / lib 的条目。 conf 默认情况下,ldconfig缓存知道我正在尝试使用的库:

k@vincent:~$ ldconfig -p | grep kaytils
        libkaytils.so.0 (libc6,x86-64) => /usr/local/lib/libkaytils.so.0
        libkaytils.so (libc6,x86-64) => /usr/local/lib/libkaytils.so

那到底是怎么回事?我在哪里可以检查默认情况下通过gcc搜索哪些库路径?也许那里出了点问题。

2 个答案:

答案 0 :(得分:7)

gcc -print-search-dirs将告诉您编译器检查的路径。 / usr / local / lib根本就不在其中,所以你的编译时链接器(在这种情况下是来自binutils的新黄金ld)在动态的时候找不到库(ld-linux.so读取由ldconfig)。据推测,您之前已经完成的构建在其makefile中添加了-L / usr / local / lib(通常由./configure脚本完成),或者您安装了二进制文件。

答案 1 :(得分:2)

这可能是环境变量的问题 - 你有一些设置包括/ usr / local / include但不包括/ usr / local / lib

来自GCC关于环境变量的图谱

       CPATH specifies a list of directories to be searched as if speci‐
       fied with -I, but after any paths given with -I options on the com‐
       mand line.  This environment variable is used regardless of which
       language is being preprocessed.

       The value of LIBRARY_PATH is a colon-separated list of directories,
       much like PATH.  When configured as a native compiler, GCC tries
       the directories thus specified when searching for special linker
       files, if it can’t find them using GCC_EXEC_PREFIX.  Linking using
       GCC also uses these directories when searching for ordinary
       libraries for the -l option (but directories specified with -L come
       first).

尝试“printenv”以查看您设置的内容

相关问题