Why do I get “undefined reference” errors even when I include the right header files?

前端 未结 5 1493
遇见更好的自我
遇见更好的自我 2021-01-04 02:51

When I tried to compile this program, it failed:

#include 
#include 
#include 
#include 

voi         


        
5条回答
  •  梦毁少年i
    2021-01-04 03:46

    Others have mentioned that you haven't linked with the pthread library using the -lpthread flag. Modern GCC (not sure how modern, mine is 4.3.3) allows you to use just -pthread. From the man page:

    -pthread
    Adds support for multithreading with the pthreads library. This option sets flags for both the preprocessor and linker.

提交回复
热议问题