Chinaunix首页 | 论坛 | 博客
  • 博客访问: 387757
  • 博文数量: 107
  • 博客积分: 2536
  • 博客等级: 少校
  • 技术积分: 781
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-14 15:19
文章分类

全部博文(107)

文章存档

2017年(11)

2016年(8)

2015年(14)

2014年(32)

2012年(1)

2011年(1)

2010年(7)

2009年(33)

我的朋友

分类: 嵌入式

2014-06-03 14:12:11

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

static sem_t            app_mutex;

void signal_handle(int signalnum)
{
    sem_wait(&app_mutex);
    printf("receive %d signal!\n",signalnum);
    sem_post(&app_mutex);
}

int main(void)
{
    int fd,oflags;
    int error = 0;

    sem_init(&app_mutex,0,1);

    fd = open("/dev/avin0",O_RDWR,S_IRUSR|S_IWUSR);
    printf("open file fd = %d\n",fd);

    if(fd != -1)
    {
        signal(SIGUSR1,signal_handle);
        signal(SIGIO,signal_handle);
        error = fcntl(fd,F_SETOWN,getpid());
        printf("error = %d,fd = %d,pid =%d\n",error,fd,getpid());
        oflags = fcntl(fd,F_GETFL);
        error = fcntl(fd,F_SETFL,oflags|FASYNC);
        printf("error = %d fd = %d oflags %#x \n",error,fd,(oflags|FASYNC));

        while(1)
        {
            sleep(1);
            printf("app run\n");
        }
    }
    else
    {
        printf("open file error\n");
    }
    return 0;
}

mips-wrs-linux-gnu-gcc -v -o avin_app.o avin_app.c

avin_app.c:(.text+0x28): undefined reference to `sem_wait'
avin_app.c:(.text+0x5c): undefined reference to `sem_post'
/tmp/ccyN5Emy.o: In function `main':
avin_app.c:(.text+0xb4): undefined reference to `sem_init'

这个是因为pthread并非Linux系统的默认库,编译时注意加上-lpthread参数,以调用链接库
我们再一次在终端输入:mips-wrs-linux-gnu-gcc -v -o avin_app.o avin_app.c -lpthread

最后需要注意的是再编译aio_read的时候

要加相应的库,-lrt


阅读(2614) | 评论(0) | 转发(0) |
0

上一篇:errno.h头文件介绍

下一篇:异步通知

给主人留下些什么吧!~~