I'm getting started with multi-thread programming using gcc under Debian 8. I've successfully written and run a multi-threaded test app (foobar.c), but I'm confused by the Makefile (copied from an example). In particular, the command that works is
gcc foobar.c -o foobar -pthread
I'm confused by "-pthread". is that
(a) an option "-p" with value "thread", or
(b) an argument "-pthread" ?
if either case, what is it actually doing? Including some library? Including some object? Setting some other option?
BTW - A similar question 15929739 was asked but never answered. Question 20924412 was not helpful either.
From the man page:
To be specific, as of GCC 6.2.1,
-pthread
will:#define _REENTRANT 1
-lpthread
to link againstlibpthread
How do I know this, you ask?
What preprocessor flags are added?
Let's dump the preprocessor defines and compare them:
What linker options are added?
Let's dump the ld options passed by GCC and compare them:
The output here is a bit more verbose, but if we ignore the temporary filename differences, we find:
-lpthread
"-plugin-opt=-pass-through=-lpthread"