Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Significance of -pthread flag when compiling

People also ask

What is flag in GCC compiler?

gcc -c compiles source files without linking.

What is the usage of flag while using it with GCC for compiling c code?

This flag helps us to specify the name of the final executable produced by GCC. It places the output of the final executable in a file “file” as specified along with the flag.

What are the purpose of the GCC flags and?

By default, GCC limits the size of functions that can be inlined. This flag allows the control of this limit for functions that are explicitly marked as inline (i.e., marked with the inline keyword or defined within the class definition in c++).

What does the wall flag do?

gcc -Wall enables all compiler's warning messages. This option should always be used, in order to generate better code.


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.


From man gcc:

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