undefined reference 'shm_open', already add -lrt flag here

前端 未结 3 1759
粉色の甜心
粉色の甜心 2020-11-29 09:23

I just have a system crash and reinstall Ubuntu 11.10, and my code produces this strange error.

I wrote a simple code sample to test where the problem is:

         


        
3条回答
  •  一向
    一向 (楼主)
    2020-11-29 09:43

    Libraries at the end:

    gcc test.c -o test -lrt

    From GCC Link Options:

    -llibrary
    -l library
        Search the library named library when linking. 
        (The second alternative with the library as a separate argument
        is only for POSIX compliance and is not recommended.)
    
        It makes a difference where in the command you write this option;
        the linker searches and processes libraries and object files in the
        order they are specified.
        Thus, `foo.o -lz bar.o' searches library `z' after file foo.o but
        before bar.o. If bar.o refers to functions in `z', those functions
        may not be loaded.
    

提交回复
热议问题