Undefined reference to pthread_create

后端 未结 5 745
北荒
北荒 2021-01-12 09:06

I have this code:

#include 
#include 

void* cuoco(void* arg)
{
    fprintf(stderr,\"Inizio codice cuoco\\n\");
    fprintf(s         


        
相关标签:
5条回答
  • 2021-01-12 09:15

    In Eclipse, you should add string pthread.

    Project -> Properties -> C/C++ Build -> Settings -> Tool Settings -> GCC Linker -> Libraries -> Libraries (-l) -> Add -> pthread

    After this, you can Build your project.

    0 讨论(0)
  • 2021-01-12 09:22

    Use the following command:

    gcc -pthread -o main main.c

    0 讨论(0)
  • Without seeing the compiler command, I suspect -lpthread is not at end. Libraries need to be placed at end of the compiler command:

    gcc main.c -lpthread

    However, use -pthread instead of -lpthread, as -pthread may add other settings (like defining the macro _REENTRANT for example).

    0 讨论(0)
  • 2021-01-12 09:31

    found the solution guys :D just go to settings >> compiler >> linker tab >>add lib

    go to drive and go to lib folder and find x86_64_linux_gnu and find pthread enjoy :)

    0 讨论(0)
  • 2021-01-12 09:38

    Use -lpthread as the last compiler flag.

    example: gcc -o sample sample.c -lpthread

    0 讨论(0)
提交回复
热议问题