求教,codeblocks在运行c++11线程是错误
codeblocks吧
全部回复
仅看楼主
level 1
北溟渔家 楼主
代码如下:
#include <thread>
#include <iostream>
#include <stdio.h>
using namespace std;
void f()
{
cout<<"success"<<endl;
}
int main(int argc, char* argv[])
{
std::thread t(f);
t.join();
return 0;
}
设置如下:
错误:
急求大神指导
2014年09月15日 08点09分 1
level 1
北溟渔家 楼主
运行环境 ubuntu14.04 gcc4.8.2
2014年09月15日 08点09分 2
level 9
Windows 下用 posix 版 mingw-w64 没问题:
2014年09月15日 09点09分 3
我在windows下用vs也没问题,到ubuntu下就不行了
2014年09月15日 09点09分
Linux下的线程,需要-pthread参数。即使你用的是C++11 thread,内部也是调用pthread,所以也需要这个参数,否则运行时std::thread找不到pthread_create函数的代码而报错。
2014年09月19日 15点09分
level 9
ubuntu 下也正常:
2014年09月15日 09点09分 4
需要配置什么东西不,你具体的环境是什么啊
2014年09月15日 09点09分
回复 北溟渔家 : 你看看我的 build log,里面都写着编译、链接开关。
2014年09月15日 09点09分
level 9
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.1 LTS
Release: 14.04
Codename: trusty
gcc --version
gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
2014年09月15日 10点09分 5
level 1
北溟渔家 楼主
我就这和你的不一样,excuting :xterm..... 是这个问题么 @天魔666
2014年09月15日 10点09分 6
还有我的g++ -o bin/Debug/test12 obj/Debug/main.o 最后是没有-pthread,这个怎么添加上的
2014年09月15日 10点09分
level 9
在 linker 的 other options 里添加。
2014年09月15日 12点09分 7
thx,搞定了
2014年09月15日 12点09分
level 8
帮顶,十五子
2014年09月15日 12点09分 8
level 1
就是这样,setting里面的linker中的other linker中添加-pthread就OK了
2016年05月10日 06点05分 10
1