ld 找不到现有的库

发布于 2024-07-09 13:11:54 字数 972 浏览 8 评论 0原文

我正在尝试在这个 Debian lenny 系统上将应用程序与 g++ 链接。 ld 抱怨找不到指定的库。 这里的具体示例是 ImageMagick,但我在使用其他一些库时也遇到了类似的问题。

我用以下命令调用链接器:

g++ -w (..lots of .o files/include directories/etc..) \
-L/usr/lib -lmagic

ld 抱怨:

/usr/bin/ld: cannot find -lmagic

但是,libmagic 存在:

$ locate libmagic.so
/usr/lib/libmagic.so.1
/usr/lib/libmagic.so.1.0.0
$ ls -all /usr/lib/libmagic.so.1*
lrwxrwxrwx 1 root root    17 2008-12-01 03:52 /usr/lib/libmagic.so.1 -> libmagic.so.1.0.0
-rwxrwxrwx 1 root root 84664 2008-09-09 00:05 /usr/lib/libmagic.so.1.0.0
$ ldd /usr/lib/libmagic.so.1.0.0 
    linux-gate.so.1 =>  (0xb7f85000)
    libz.so.1 => /usr/lib/libz.so.1 (0xb7f51000)
    libc.so.6 => /lib/i686/cmov/libc.so.6 (0xb7df6000)
    /lib/ld-linux.so.2 (0xb7f86000)
$ sudo ldconfig -v | grep "libmagic"
    libmagic.so.1 -> libmagic.so.1.0.0

如何进一步诊断此问题,可能出了什么问题? 我在做一些完全愚蠢的事情吗?

I am attempting to link an application with g++ on this Debian lenny system. ld is complaining it cannot find specified libraries. The specific example here is ImageMagick, but I am having similar problems with a few other libraries too.

I am calling the linker with:

g++ -w (..lots of .o files/include directories/etc..) \
-L/usr/lib -lmagic

ld complains:

/usr/bin/ld: cannot find -lmagic

However, libmagic exists:

$ locate libmagic.so
/usr/lib/libmagic.so.1
/usr/lib/libmagic.so.1.0.0
$ ls -all /usr/lib/libmagic.so.1*
lrwxrwxrwx 1 root root    17 2008-12-01 03:52 /usr/lib/libmagic.so.1 -> libmagic.so.1.0.0
-rwxrwxrwx 1 root root 84664 2008-09-09 00:05 /usr/lib/libmagic.so.1.0.0
$ ldd /usr/lib/libmagic.so.1.0.0 
    linux-gate.so.1 =>  (0xb7f85000)
    libz.so.1 => /usr/lib/libz.so.1 (0xb7f51000)
    libc.so.6 => /lib/i686/cmov/libc.so.6 (0xb7df6000)
    /lib/ld-linux.so.2 (0xb7f86000)
$ sudo ldconfig -v | grep "libmagic"
    libmagic.so.1 -> libmagic.so.1.0.0

How do I diagnose this problem further, and what could be wrong? Am I doing something completely stupid?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

日记撕了你也走了 2024-07-16 13:11:54

问题是链接器正在寻找 libmagic.so 但你只有 libmagic.so.1

一个快速的技巧是符号链接 libmagic.so.1代码>到libmagic.so

The problem is the linker is looking for libmagic.so but you only have libmagic.so.1

A quick hack is to symlink libmagic.so.1 to libmagic.so

因为看清所以看轻 2024-07-16 13:11:54

正如grepsedawk刚刚表述的那样,答案在于g++-l选项,调用ld。 如果您查看此命令的手册页,您可以执行以下操作:

  • g++ -l:libmagic.so.1 [...]
  • 或:g++ -lmagic [...] ,如果您的库路径中有一个名为 libmagic.so 的符号链接

As just formulated by grepsedawk, the answer lies in the -l option of g++, calling ld. If you look at the man page of this command, you can either do:

  • g++ -l:libmagic.so.1 [...]
  • or: g++ -lmagic [...] , if you have a symlink named libmagic.so in your libs path
不爱素颜 2024-07-16 13:11:54

Debian 约定将共享库分为运行时组件 (libmagic1: /usr/lib/libmagic.so.1 → libmagic.so.1.0.0) 及其开发组件 (libmagic) -dev: /usr/lib/libmagic.so → ...)。

因为库的soname 是libmagic.so.1,所以它是嵌入到可执行文件中的字符串,因此这是运行可执行文件时加载的文件。

但是,由于该库被指定为链接器的 -lmagic,因此它会查找 libmagic.so,这就是开发需要它的原因。

请参阅 Diego E. Pettenò:链接器和名称,了解这一切在 Linux 上如何工作的详细信息。


简而言之,您应该apt-get install libmagic-dev。 这不仅会为您提供 libmagic.so,还会提供编译所需的其他文件,例如 /usr/include/magic.h

It is Debian convention to separate shared libraries into their runtime components (libmagic1: /usr/lib/libmagic.so.1 → libmagic.so.1.0.0) and their development components (libmagic-dev: /usr/lib/libmagic.so → …).

Because the library's soname is libmagic.so.1, that's the string that gets embedded into the executable so that's the file that is loaded when the executable is run.

However, because the library is specified as -lmagic to the linker, it looks for libmagic.so, which is why it is needed for development.

See Diego E. Pettenò: Linkers and names for details on how this all works on Linux.


In short, you should apt-get install libmagic-dev. This will not only give you libmagic.so but also other files necessary for compiling like /usr/include/magic.h.

好听的两个字的网名 2024-07-16 13:11:54

在 Ubuntu 中,您可以安装 libtool 来自动解析库。

$ sudo apt-get install libtool

这为我解决了 ltdl 的问题,它已作为 libltdl.so.7 安装,并且在以下位置中找不到简单的 -lltdl品牌。

In Ubuntu, you can install libtool which resolves the libraries automatically.

$ sudo apt-get install libtool

This resolved a problem with ltdl for me, which had been installed as libltdl.so.7 and wasn't found as simply -lltdl in the make.

魂归处 2024-07-16 13:11:54

如上所述,链接器正在寻找 libmagic.so,但您只有 libmagic.so.1

要解决这个问题,只需执行更新缓存即可。

ldconfig -v 

要验证您可以运行:

$ ldconfig -p | grep libmagic

As mentioned above the linker is looking for libmagic.so, but you only have libmagic.so.1.

To solve this problem just perform an update cache.

ldconfig -v 

To verify you can run:

$ ldconfig -p | grep libmagic
梨涡少年 2024-07-16 13:11:54

除非我严重错误 libmagic-lmagic 与 ImageMagick 不是同一个库。 您声明您想要 ImageMagick。

ImageMagick 附带了一个实用程序,可为编译器提供所有适当的选项。

前任:

g++ program.cpp `Magick++-config --cppflags --cxxflags --ldflags --libs` -o "prog"

Unless I'm badly mistaken libmagic or -lmagic is not the same library as ImageMagick. You state that you want ImageMagick.

ImageMagick comes with a utility to supply all appropriate options to the compiler.

Ex:

g++ program.cpp `Magick++-config --cppflags --cxxflags --ldflags --libs` -o "prog"
巾帼英雄 2024-07-16 13:11:54

从 Ubuntu 存储库安装 libgl1-mesa-dev 为我解决了这个问题。

Installing libgl1-mesa-dev from the Ubuntu repo resolved this problem for me.

内心荒芜 2024-07-16 13:11:54

我尝试了上面提到的所有解决方案,但没有一个解决了我的问题,但最后我用以下命令解决了它。

sudo apt-get install libgmp3-dev

这会发挥魔法。

I tried all solutions mentioned above but none of them solved my issue but finally I solved it with the following command.

sudo apt-get install libgmp3-dev

This will do the magic.

你的往事 2024-07-16 13:11:54

解决此问题的另一种方法是安装 -devel 包。

如果编译器正在寻找 libabc.so,而您有 libabc.so.1,则需要安装 -devel 软件包,例如 libabc-devel as libabc.so.1 是一个运行时库,但 libabc.so 是一个开发库。

Another way to solve this problem is to install the -devel package.

If the compiler is looking for libabc.so while you have libabc.so.1, you need to install the -devel package like libabc-devel as libabc.so.1 is a runtime lib but libabc.so is a development lib.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文