Significance of -pthread flag when compiling

前端 未结 2 809
轻奢々
轻奢々 2020-11-22 07:41

In various multi threaded C and C++ projects I\'ve seen the -pthread flag applied to both the compiling and linking stage while others don\'t use it at all and

相关标签:
2条回答
  • 2020-11-22 08:19

    Try:

    gcc -dumpspecs | grep pthread
    

    and look for anything that starts with %{pthread:.

    On my computer, this causes files to be compiled with -D_REENTRANT, and linked with -lpthread. On other platforms, this could differ. Use -pthread for most portability.

    Using _REENTRANT, on GNU libc, changes the way some libc headers work. As a specific example, it makes errno call a function returning a thread-local location.

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

    From man gcc:

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

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