linux - 在 Linux 上使用 POSIX AIO 库编译 C++ 程序

标签 linux file posix aio

在 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/

相关文章:

c - 有没有一种编程方法可以判断符号链接(symbolic link)是否指向 C 中的文件或目录?

c - stat 的 st_blksize 是以位还是字节为单位测量的?

c - libc 源位置 - 用于下载或在线查看?

c - 为什么程序卡在 child 与 parent 的沟通上?

linux - Linux 中动态库导出/导入的关键字是什么?

从 FTP 服务器检索 Java 文件

python - 打开用于写入和读取大文件的Python

c++ - Linux:有没有办法在不停止/暂停进程(SIGSTOP)的情况下使用 ptrace?

在linux中从C代码调用汇编函数

java - 如何在 Android 上将文件从内部应用存储移动/重命名到外部存储?