Hi
I am running Eclipse Mars on Fedora 23.
I have written a tiny program that uses the C++11 threads class.
#include <iostream>
#include <thread>
using namespace std;
// This function will be called from a thread
void call_from_thread()
{
cout << "!!!Hello World!!!" << endl;
}
int main()
{
// Launch a thread
std::thread t1(call_from_thread);
// Join the thread with main thread
t1.join();
return 0;
}
I've configured the project to use C++11 dialect as described here:
https://wiki.eclipse.org/CDT/User/FAQ#CDT_does_not_recognize_C.2B.2B11_features
I also tried the "-std=c++11" compiler spec.
After re-indexing there are no indexer or compiler errors but at runtime I get a linker error:
16:59:36 **** Build of configuration Debug for project solarion_tutorial ****
make all
Building file: ../src/solarion_tutorial.cpp
Invoking: GCC C++ Compiler
g++ -std=c++0x -I"-l pthread" -O0 -g3 -Wall -c -fmessage-length=0 -std=c++11 -MMD -MP -MF"src/solarion_tutorial.d" -MT"src/solarion_tutorial.o" -o "src/solarion_tutorial.o" "../src/solarion_tutorial.cpp"
Finished building: ../src/solarion_tutorial.cpp
Building target: solarion_tutorial
Invoking: GCC C++ Linker
g++ -o "solarion_tutorial" ./src/solarion_tutorial.o
./src/solarion_tutorial.o: In function `std::thread::thread<void (&)()>(void (&)())':
/usr/include/c++/5.3.1/thread:137: undefined reference to `pthread_create'
I've tried adding "-l pthread" as an include path but that didn't fix it. But I guess I shouldn't need to do that if I am using C++11?
Can anyone help please?
David