c -/usr/bin/ld : cannot find shared library

标签 c gcc shared-libraries

我在/usr/local/lib 中有 libcommon.so,我正在我的程序中链接这个库。

gcc -o test test_prog.c -L/usr/local/lib -llibcommon.so

我也试过

gcc -o test test_prog.c -L/usr/local/lib -llibcommon

付出

/usr/bin/ld: cannot find -llibcommon.so
collect2: ld returned 1 exit status

它在那里:

$ locate libcommon.so
/usr/local/lib/libcommon.so
/usr/local/lib/libcommon.so.0
/usr/local/lib/libcommon.so.0.1.0
$

最佳答案

当您使用 -l 时,您只需指定“基本”库名称:

-lcommon

这将在某个目录中找到 libcommon.so

您告诉编译器尝试查找 liblibcommon.so.so(和 liblibcommon.so),但它可能找不到……事实上,您不会如果可以,请不要问这个问题。

一些 GNU 程序构建了一个库 libiberty.so(或其等价物),因此使用该库的链接行链接到:

-liberty

(这很有趣;GNU 真的更希望它是 +liberty,但是……你不能解决所有问题)。

关于c -/usr/bin/ld : cannot find shared library,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18639723/

相关文章:

gcc - RISC-V : Minimum CSR requirements for simple RV32I implementation capable of leveraging GCC

c - MinGW 海湾合作委员会 : "Unknown conversion type character ' h'"(snprintf)

c - 动态共享库加载框架

c - 使用冒泡排序对指针数组进行排序,返回未排序的数组

在C中将十进制数转换为十六进制数

c++ - Visual Studio 仅在当前文件中转到书签

c - Fastest 3, unsigned short Max/Min OR Sort for RGB -> HUE calc, 图形特定

c++ - gcc reverse_iterator 比较运算符丢失了吗?

c++ - 允许共享库中 undefined reference 的 g++ 标志是什么?

mysql - ./configure 在树莓派 3 上找不到 libmysqlclient 库,无法链接