I was trying to compile some multithreading code on different gcc
versions on travis-ci
. The versions that were used for the build were: g++ 4.8
and g++ 4.9
. The code would refuse to compile without -lpthread
on both versions. On adding the -lpthread
flag however, they would compile, but when run, the g++ 4.8
code just crashed, while g++ 4.9
seemed to have build the right compilation. Now, when I changed the flag to -pthread
on both compilers, both built correctly. I understand, -lpthread
links with the C-style
thread library, while -pthread
causes the compiler to link the correct library, which 'might' not be the C-style
thread library. Am I correct? Here's the link to the two build-logs: gcc 4.8 and gcc 4.9.
Asked
Active
Viewed 1,437 times
1

user2338150
- 479
- 5
- 14
-
5Possible duplicate of [gcc - significance of -pthread flag when compiling](https://stackoverflow.com/questions/2127797/gcc-significance-of-pthread-flag-when-compiling) – n. m. could be an AI Jul 31 '17 at 06:33
-
Exact duplicate! :) Thanks! – user2338150 Aug 02 '17 at 05:35