Possible Duplicate:
gcc - significance of -pthread flag when compiling
Currently I am working on a multi-thread project. I found that GCC 4.4 has already supported std::thread if given -std=c++0x option. I wrote a test program test_thread.cpp as follows:
#include <iostream>
#include <thread>
void my_thread_func()
{
std::cout<<"hello"<<std::endl;
}
int main()
{
std::thread t(my_thread_func);
t.join();
return 0;
}
If I compile and link it with
g++ -Wall -O2 -std=c++0x -c test_thread.cpp
g++ -Wall -O2 -o test_thread test_thread.o
Then I got a "Segmentation fault" error. I read the GCC manual and found that I should add -pthread options to both compile and link. This could work for me. If I add -lpthread, this works too. I want to know the differences between these two options "-pthread" and "-lpthread", thank you.