关于在ubuntu下eclipse中c++11支持和编译运行c++11报错的解决方法
2016-01-14 20:44
766 查看
最近准备升级项目中的c++线程部分代码用c++11简单重构一下,结果测试demo直接就报错~
百度和谷歌了一部分还是没有解决这个问题~
最后经过研究eclipse的自动编译~终于搞定了~
首先按照网上说的~ http://hkllzh.iteye.com/blog/1620352 配置eclipse的编译参数,我的平台是ubuntu14 64位 3.11.0-26-generic
编译通过了,运行报错:
后来在谷歌找到 : http://stackoverflow.com/questions/21129735/g-4-8-1-c-threads-stdsystem-error-operation-not-permitted
需要添加
在C/C++
Build --> Settings --> Tool Settings --> GCC C++ Compiler --> Miscellanous中添加这个编译参数
然后发现还是不行-_-#
后来根据eclipse输出
[cpp] view
plaincopy
make all
Building file: ../src/TestC11.cpp
Invoking: GCC C++ Compiler
g++ -D__GXX_EXPERIMENTAL_CXX0X__ -O0 -g3 -Wall -c -fmessage-length=0 -pthread -std=c++0x -Wl,--no-as-needed -MMD -MP -MF"src/TestC11.d" -MT"src/TestC11.d" -o "src/TestC11.o" "../src/TestC11.cpp"
Finished building: ../src/TestC11.cpp
Building target: TestC11
Invoking: GCC C++ Linker
g++ -o "TestC11" ./src/TestC11.o
Finished building target: TestC11
发现了问题~eclipse是先编译成静态库然后生成可执行文件,那么要在链接阶段添加这个参数而不是编译阶段~~~
那么在C/C++ Build --> Settings --> Tool Settings --> GCC C++ Linker --> Miscellanous 添加,在原先编译参数的地方删除
再次clean - build - run 执行成功~
================================================= 别高兴的太早 =================================================
回到eclipse一看~诶~编译运行时通过了~但是代码中还是报错~thread类找不到,并且自动提示也没有,那还敲什么代码~~~
进入头文件<thread>查看发现thread声明有宏定义,并且
[cpp] view
plaincopy
#if __cplusplus < 201103L
# include <bits/c++0x_warning.h>
#else
...
#endif
并且
[cpp] view
plaincopy
__cplusplus 199711L
恩~上面添加的c++11支持并没有在代码检查中生效~
最后查到设置在
[html] view
plaincopy
Workspace settings
Window-> Preference -> Build -> Settings -> Discovery -> CDT GCC Built-in Compiler Settings(shared) 中的
(command to get compiler specs) 改为 ${COMMAND} -E -P -v -dD ${INPUTS} -std=c++11
最后还要重新新建工程~刷新或者改工程中的
[html] view
plaincopy
CDT GCC Built-in Compiler Settings(shared)
参数也是不行的~必须新建一个~
百度和谷歌了一部分还是没有解决这个问题~
最后经过研究eclipse的自动编译~终于搞定了~
首先按照网上说的~ http://hkllzh.iteye.com/blog/1620352 配置eclipse的编译参数,我的平台是ubuntu14 64位 3.11.0-26-generic
编译通过了,运行报错:
[code]terminate called after throwing an instance of 'std::system_error' what(): Enable multithreading to use std::thread: Operation not permitted Aborted (core dumped)
后来在谷歌找到 : http://stackoverflow.com/questions/21129735/g-4-8-1-c-threads-stdsystem-error-operation-not-permitted
需要添加
[code]-Wl,--no-as-needed -pthread
在C/C++
Build --> Settings --> Tool Settings --> GCC C++ Compiler --> Miscellanous中添加这个编译参数
然后发现还是不行-_-#
后来根据eclipse输出
[cpp] view
plaincopy
make all
Building file: ../src/TestC11.cpp
Invoking: GCC C++ Compiler
g++ -D__GXX_EXPERIMENTAL_CXX0X__ -O0 -g3 -Wall -c -fmessage-length=0 -pthread -std=c++0x -Wl,--no-as-needed -MMD -MP -MF"src/TestC11.d" -MT"src/TestC11.d" -o "src/TestC11.o" "../src/TestC11.cpp"
Finished building: ../src/TestC11.cpp
Building target: TestC11
Invoking: GCC C++ Linker
g++ -o "TestC11" ./src/TestC11.o
Finished building target: TestC11
发现了问题~eclipse是先编译成静态库然后生成可执行文件,那么要在链接阶段添加这个参数而不是编译阶段~~~
那么在C/C++ Build --> Settings --> Tool Settings --> GCC C++ Linker --> Miscellanous 添加,在原先编译参数的地方删除
[code]-Wl,--no-as-needed -pthread
再次clean - build - run 执行成功~
================================================= 别高兴的太早 =================================================
回到eclipse一看~诶~编译运行时通过了~但是代码中还是报错~thread类找不到,并且自动提示也没有,那还敲什么代码~~~
进入头文件<thread>查看发现thread声明有宏定义,并且
[cpp] view
plaincopy
#if __cplusplus < 201103L
# include <bits/c++0x_warning.h>
#else
...
#endif
并且
[cpp] view
plaincopy
__cplusplus 199711L
恩~上面添加的c++11支持并没有在代码检查中生效~
最后查到设置在
[html] view
plaincopy
Workspace settings
Window-> Preference -> Build -> Settings -> Discovery -> CDT GCC Built-in Compiler Settings(shared) 中的
(command to get compiler specs) 改为 ${COMMAND} -E -P -v -dD ${INPUTS} -std=c++11
最后还要重新新建工程~刷新或者改工程中的
[html] view
plaincopy
CDT GCC Built-in Compiler Settings(shared)
参数也是不行的~必须新建一个~
相关文章推荐
- C语言实现封装、继承和多态
- c++之路进阶——块状链表(弹飞绵羊)
- 适配器模式 C++实现
- 基于 intel MKL 的对称矩阵特征值求解器
- [转] C语言常见笔试题大全1
- c++之路进阶——块状链表(教主的魔法)
- C++实现单链表
- C/C++——sizeof和strlen的区别
- C++预定义字符函数
- vc++ 读取指定文件夹下所有文件名
- 2、C++
- C++基础篇 -- vector的resize函数和reserve函数
- C语言文件打开模式(r/w/a/r+/w+/a+/rb/wb/ab/rb+/wb+/ab+)浅析
- 【C++】【斐波那契】求第几个斐波那契数字。
- RHEL安装 C++ 编译器
- C++有哪几种情况只能用初始化列表,而不能用赋值?
- IOS 学习第七天 C语言 数组
- C/C++文件读写
- C++学习之对象成员指针篇
- C语言中指针与java