美文网首页
undefined reference to sem_open

undefined reference to sem_open

作者: 1Z实验室阿凯 | 来源:发表于2016-04-06 07:57 被阅读389次

    加了semaphore.h ,还报错undefined reference to sem_open

    ERROR

    scorpion@Turing-Machine:~/OSLearn/OS-Assignment-2016/4_Linux_Progress_Control/4_5_shared_memory$ make
    cc -c init.c
    cc -o edit init.o common.o
    common.o: In function `SemInit':
    common.c:(.text+0x7f): undefined reference to `sem_open'
    common.c:(.text+0xa2): undefined reference to `sem_open'
    common.o: In function `SemDestroy':
    common.c:(.text+0xc6): undefined reference to `sem_open'
    common.c:(.text+0xe3): undefined reference to `sem_open'
    common.c:(.text+0xf3): undefined reference to `sem_close'
    common.c:(.text+0x102): undefined reference to `sem_unlink'
    common.c:(.text+0x10e): undefined reference to `sem_close'
    common.c:(.text+0x11d): undefined reference to `sem_unlink'
    common.o: In function `P':
    common.c:(.text+0x138): undefined reference to `sem_wait'
    common.o: In function `V':
    common.c:(.text+0x153): undefined reference to `sem_post'
    collect2: error: ld returned 1 exit status
    makefile:4: recipe for target 'edit' failed
    make: *** [edit] Error 1
    
    
    

    SOLUTION
    编译的时候添加 -pthread ?
    以为关于Posix的库文件不包含在Linux的默认库中 所以需要添加-pthread参数

    gcc -pthread -o init init.o common.o
    

    在makefile中的书写方法

    DONE

    "undefined reference to" 问题解决方法 ‘

    相关文章

      网友评论

          本文标题:undefined reference to sem_open

          本文链接:https://www.haomeiwen.com/subject/azaplttx.html