Compiling a program in C ++ using POSIX AIO lib on Linux

I am having difficulty with the linker when it comes to compiling an example program that uses the POSIX aio library (like aio_read (), aio_write (), etc.) on Linux.

I am running Ubuntu with a 2.6 kernel and used the apt-get utility to install libaio. But even if I contact the aio library, the compiler still gives me linker errors.

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

Where are all these aio_x functions actually defined, if not in the libaio.a library?

+3
source share
6 answers

EDIT: according to the man page, libaio.so is not the right library to link to:

man aio_read

SYNTAX

   #include <aio.h>

   int aio_read(struct aiocb *aiocbp);

   Link with -lrt.

:

g++ -lrt aio.cc -o aio

gcc :

-L , , -l.

-l , libsomename.so, "-lomename"

+7

, libaio, aio -lrt.

, -l (, ) gcc . .

:

gcc -Wall -Werror -g -o myExe -lrt myExe.c

:

gcc -Wall -Werror -g -o myExe myExe.c -lrt
+7

-L -l ?

0

Try:

sudo apt-get install libaio-dev

Then, make sure you point -laioto the link line.

0
source

You want -laioto link to libaio. The argument -ois that you want the compiled executable to be called.

0
source

Well, Evan Teran is right - it worked when I contacted -lrt. It seems the aio_x functions are defined in the shared POSIX extension library.

Thanks, Evan.

0
source

Source: https://habr.com/ru/post/1714143/


All Articles