LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   asynchronous I/O for Linux 2.6 problems.... (https://www.linuxquestions.org/questions/programming-9/asynchronous-i-o-for-linux-2-6-problems-532927/)

Petros Koutoupis 02-27-2007 09:29 AM

asynchronous I/O for Linux 2.6 problems....
 
I have been trying to resolve this for a short while now and I am getting very frustrated. I have been attempting to write a simple program for asynchronous I/O, make sure it works and then eventually merge it into the main branch of our company's I/O utility. Here is the source:
Code:

#define _USE_GNU
#define _GNU_SOURCE
#define _XOPEN_SOURCE 600
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <aio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(int argc, char *argv[])
{
        int status;
        struct aiocb myaio;
        myaio.aio_fildes = open(argv[1], O_RDONLY | O_DIRECT);
        if(myaio.aio_fildes == -1)
        {
                perror("open");
                exit(0);
        }
        myaio.aio_nbytes = 512;
        myaio.aio_offset = 0;
        posix_memalign((void *)&myaio.aio_buf, 512, 512);
        status = aio_read(&myaio);
        //rest of code is irrelevant, it cannot seem to properly input
        //the reference of myaio into aio functions such as aio_read/aio_write
        return 0;
}

Here is the error I get during the compilation/linking process:
Code:

/tmp/ccAtflgo.o(.text+0x8f): In function `main':
: undefined reference to `aio_read'
collect2: ld returned 1 exit status

I have even looked at aio examples off of the net to find that they are exactly like mine and error out exactly like mine. I am working with linux kernels 2.6.9-x and 2.6.16-x. Are there any known problems with aio or what am I doing wrong? Thanks in advance.

jim mcnamara 02-27-2007 03:17 PM

gcc -lrt -Wall -o myaio myaio.c

Petros Koutoupis 02-27-2007 03:57 PM

Thanks, cleanly compiles/links. I never thought about invoking gcc with the recommended switches.


All times are GMT -5. The time now is 11:20 PM.