Undefined reference to pthread_create in Linux

后端 未结 14 2337
梦毁少年i
梦毁少年i 2020-11-22 03:18

I picked up the following demo off the web from https://computing.llnl.gov/tutorials/pthreads/

#include 
#include 
#define NU         


        
相关标签:
14条回答
  • 2020-11-22 04:01

    For Linux the correct command is:

    gcc -o term term.c -lpthread
    
    1. you have to put -lpthread just after the compile command,this command will tell to the compiler to execute program with pthread.h library.
    2. gcc -l links with a library file.Link -l with library name without the lib prefix.
    0 讨论(0)
  • 2020-11-22 04:02

    If you are using cmake, you can use:

    add_compile_options(-pthread)
    

    Or

    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
    
    0 讨论(0)
  • 2020-11-22 04:08

    in eclipse

    properties->c/c++Build->setting->GCC C++ linker->libraries in top part add "pthread"

    0 讨论(0)
  • 2020-11-22 04:08

    you need only Add "pthread" in proprieties=>C/C++ build=>GCC C++ Linker=>Libraries=> top part "Libraries(-l)". thats it

    0 讨论(0)
  • 2020-11-22 04:09

    In Visual Studio 2019 specify -pthread in the property pages for the project under:

    Linker -> Command Line -> Additional Options

    Type in -pthread in the textbox.

    0 讨论(0)
  • 2020-11-22 04:10

    Sometimes, if you use multiple library, check the library dependency. (e.g. -lpthread -lSDL... <==> ... -lSDL -lpthread)

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