当在Linux上编译一个使用POSIX库(例如aio_read(),aio_write()等)的示例程序时,我遇到了链接器方面的困难。
我使用2.6内核运行Ubuntu,并使用apt-get实用程序安装libaio。但是,即使我链接了aio库,编译器仍然给我提供了链接器错误。
root@ubuntu:/home# g++ -L /usr/lib/libaio.a aio.cc -oaio
/tmp/cc5OE58r.o: In function `main':
aio.cc:(.text+0x156): undefined reference to `aio_read'
aio.cc:(.text+0x17b): undefined reference to `aio_error'
aio.cc:(.text+0x191): undefined reference to `aio_return'
collect2: ld returned 1 exit status如果不是在liaio.a库中,那么所有这些aio_x函数都是在哪里实际定义的?
发布于 2014-12-15 22:10:25
尽管aio包安装正确并且存在-lrt标志,但我还是遇到了链接libaio的问题。
事实证明,在gcc命令调用中将-l标志放在后面(例如,最后)有时可以解决这个问题。我偶然发现了这个解决方案here on Stack Overflow。
我不再这样做了:
gcc -Wall -Werror -g -o myExe -lrt myExe.c并开始这样做:
gcc -Wall -Werror -g -o myExe myExe.c -lrt发布于 2009-08-01 23:24:23
EDIT:根据手册页,libaio.so不是要链接的正确库:
man aio_read
概要
#include int aio_read(struct aiocb *aiocbp);链接-lrt。
因此,您应该链接以下内容:
g++ -lrt aio.cc -o aio图书馆与gcc的合作方式是这样的:
-l将目录dir添加到要搜索-L的目录列表中。
-l本身添加了一个库,如果文件名为libsomename.so,只需使用"-lsomename“
发布于 2009-08-01 23:20:52
-L是否指定了搜索路径,而-l是否指定了实际库?
https://stackoverflow.com/questions/1217705
复制相似问题