在 Linux 上编译使用 POSIX aio 库(例如 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
如果不在库 libaio.a 中,所有这些 aio_x 函数实际上在哪里定义?
最佳答案
尽管正确安装了 aio 包并且存在 -lrt
标志,但我在链接 libaio
时也遇到了问题。
事实证明,稍后(例如,最后)在 gcc
命令调用中放置 -l
标志有时可以解决此问题。我偶然发现了这个解决方案 here在 Stack Overflow 上。
我停止这样做了:
gcc -Wall -Werror -g -o myExe -lrt myExe.c
然后开始这样做:
gcc -Wall -Werror -g -o myExe myExe.c -lrt
关于linux - 在 Linux 上使用 POSIX AIO 库编译 C++ 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1217705/