Linux C++:libaio.h 不包含 io_context_t 的定义?

linux C++: libaio.h doesn't contain definition for io_context_t?

本文关键字:context 定义 io 包含 C++ libaio Linux      更新时间:2023-10-16

我有一个超级简单的.cpp文件,如下所示:

    $cat test001.cpp
    #include<libaio.h>
    int main(){
        io_context_t ctx={0};
        struct iocb io,*p=&io;
        return 0;
    }

但是,一旦用GCC 4.1.2编译,它会提示错误:

    $g++ test001.cpp -laio
    test001.cpp:1:19: error: libaio.h: No such file or directory
    test001.cpp: In function ‘int main()’:
    test001.cpp:3: error: ‘io_context_t’ was not declared in this scope
    test001.cpp:3: error: expected `;' before ‘ctx’
    test001.cpp:4: error: aggregate ‘iocb io’ has incomplete type and cannot be defined

好吧,我已经在使用" libaio.h"。为什么仍然失败?

sudo apt-get install libaio-dev肯定应该解决问题。它用于Linux内核AIO访问库 - 开发文件。