简体   繁体   English

编译C源代码时(不兼容的库)找不到-lagent

[英]Cannot find -lagent when compiling c source code (incompatible library)

With gcc in ubuntu I used this command to compile my source code: 在ubuntu中使用gcc时,我使用以下命令来编译源代码:

gcc 1.c -L. -lagent -lm -lpthread -o 1

but I got this error: 但是我得到了这个错误:

/usr/bin/ld: skipping incompatible ./libagent.so when searching for -lagent
/usr/bin/ld: cannot find -lagent
collect2: ld returned 1 exit status

How can I solve this? 我该如何解决?

The linker is telling you that the file ./libagent.so exists, but isn't in the appropriate format . 链接器告诉您./libagent.so文件存在,但格式不正确

It could be an empty file, or built for 32-bit instead of 64-bit, or it could be a symlink pointing to the wrong version. 它可能是一个空文件,或者是为32位而不是64位构建的,或者它可能是指向错误版本的符号链接。

Let's look at your command line parameters first. 首先让我们看看您的命令行参数。

gcc 1.c -L. -lagent -lm -lpthread -o 1

You call the compiler gcc with the input source code of 1.c and then you specify an additional (link) library path to include the current directory ( . ) -L. 您使用输入源代码1.c调用编译器gcc ,然后指定其他(链接)库路径以包含当前目录( . )- -L. . Then you tell it to link against the agent and pthread libraries, where shared (dynamic) libraries have the default name format of libNAME.so where NAME is replaced with the name. 然后,您告诉它链接到代理和pthread库,共享(动态)库的默认名称格式为libNAME.so,其中NAME被替换为名称。 Static libraries have the default file extension .a (from the term archive ). 静态库具有默认文件扩展名.a (来自术语archive )。 Then you specify the output (executable in this case) to be the file 1 (digit one, not the letter 'ell'). 然后,将输出(在这种情况下是可执行的)指定为文件1 (数字1,而不是字母“ ell”)。

/usr/bin/ld: skipping incompatible ./libagent.so when searching for -lagent

This is the linker ( ld ) telling you that the file ./libagent.so (it found presumably in the current directory) is not a valid shared library format as it was expecting. 这是链接程序( ld ),告诉您./libagent.so文件(可能在当前目录中找到)不是预期的有效共享库格式。 This could be for a different machine architecture (x86-64, ARMle, PowerPC, MIPS) or a incompatible library format (I don't know if library files, .so, have any COFF or ELF or PE dependencies or not). 这可能适用于不同的计算机体系结构(x86-64,ARMle,PowerPC,MIPS)或不兼容的库格式(我不知道库文件.so是否具有COFFELFPE依赖项)。 Or simply otherwise empty or corrupted (eg interrupted output due to errors compiling / linking). 或者只是因为其他原因而变空或损坏(例如,由于编译/链接错误而导致输出中断)。

So you normally want to not include your current directory in your linker's search path, unless you have the copy of the library that you have not yet installed (typically to /usr/lib/ or /usr/local/lib/), such as you wrote the library and wish to link test programs to it before you install it. 因此,通常, 除非您拥有尚未安装的库的副本(通常是/ usr / lib /或/ usr / local / lib /), 否则通常不要在链接程序的搜索路径中包括当前目录。您编写了该库,并希望在安装它之前将测试程序链接到它。

Debian and Unbuntu-oriented part of the answer: 面向Debian和Unbuntu的部分答案:

Normally you want to install shared library's runtime component (often named something like libagent ) and the associated development files (most often at least a header file and hopefully a manpage) in the format libagent-dev . 通常,您需要以libagent-dev格式安装共享库的运行时组件(通常命名为libagent类的libagent )和相关的开发文件(通常至少是一个头文件,并希望有一个联机帮助页)。 RPM based Linux systems use libagent-devel style naming conventions (from memory). 基于RPM的Linux系统使用libagent-devel样式命名约定(来自内存)。 So sudo aptitude install libagent-dev should do the trick if that is the package's name. 因此,如果这是软件包的名称,那么sudo aptitude install libagent-dev应该可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM