开发者

How to compile and run C++0x with GCC/G++ in Eclipse CDT?

I am trying to figure out how to use the upcoming C++ release 0x. It should be available in GCC 4.3+ with using the gcc std=gnu++0x option.

My simple thread program using 0x compiles in Eclipse CDT with std=gnu++0x added in Project > properties > C/C++ Build > Settings > Miscellaneous > Other flags.

#include <iostream>
#include <thread>
using namespace std;

void hello()
{
    cout << "Hello Concurrent World开发者_JAVA百科!" << endl;
}

int main()
{
    cout << "starting" << endl;
    thread t(hello);
    t.join();
    cout << "ending" << endl;
    return 0;
}

The program only prints "starting" and returns 0. Does anyone know why it does not run the hello function threaded?


To use threads you also need to link against the threading library. In case you haven't done that add -lpthread to your command line or in your case to other flags field.

The command line execute (visible in your console window in eclipse) should look like this:

gcc -std=gnu++0x -lpthread <source_file_name>.cc

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜