Search code examples
c++linuxincludedefinitionaio

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


I've got a super simple .cpp file like below:

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

But once compile it with gcc 4.1.2, it prompts error:

    $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

Well I'm already using "libaio.h". Why it still fails?


Solution

  • sudo apt-get install libaio-dev It should definitely fix the issue. It is for Linux kernel AIO access library - development files.