配置C++17开发环境的codeblock&&eclipse

来源:互联网 发布:vc编程入门 编辑:程序博客网 时间:2024/05/16 07:48

本人QQ970026607 有问题可联系

参考博客:
http://blog.csdn.net/u013595419/article/details/45538605
http://blog.csdn.net/kiritow/article/details/53311570
http://blog.csdn.net/Just_Do_IT_Ye/article/details/47615153

Window平台下,百度搜索TDM-GCC发现只有5.1.0版本,恩,感觉这好像不支持c++17,百度进入gcc官网,目前最近的版本是7.1.0是支持c++17的(亲测)

那就换个平台吧 我的是:linux-ubuntu-16.04

第一步:到官网[https://gcc.gnu.org/](https://gcc.gnu.org/)下载gcc7.1.0版本的gz 包。然后解压(图形界面右键提取到..,命令行tar -xf gcc-7.1.0.tar.gz)
第二步:进入你解压的所在的目录,运行在contrib目录的download_prerequisites脚本, 命令如下./contrib/download_prerequisites (这个脚本下载所需要的依赖文件和库) 
第三步执行./configure --prefix=/usr/local --program-suffix=-.1.0 --enable-threads=posix --enable-languages=c,c++ --disable-multilib  
第四步执行make  (耗时2~3)小时
第五步执行sudo make install 
然后gcc就下载到/usr/local/bin 这个目录里了。如果你以前下载过gcc ,可以用gcc -v 查看到以前的版本新的版本通过gcc-7.1.0 -v查看
  **先用apt-get remove --purge gcc把原来装的gcc卸载了吧**  接着,配置gcc-7.1.0环境变量    ln -s /usr/local/bin/gcc-5.1.0 /usr/bin/gcc      ln -s /usr/local/bin/g++-5.1.0 /usr/bin/g++      ln -s /usr/local/bin/c++-5.1.0 /usr/bin/c++    然后用 gcc -v检查效果如下则正常

这里写图片描述

这是一段c++17才能编译通过的代码,在home新建一个abc.cpp,复制如下内容

#include <variant>#include <string>#include <cassert>#include <stdio.h>using namespace std::literals;int main(){    std::variant<int, float> v, w;    v = 12; // v contains int    int i = std::get<int>(v);    w = std::get<int>(v);    w = std::get<0>(v); // same effect as the previous line    w = v; // same effect as the previous line//  std::get<double>(v); // error: no double in [int, float]//  std::get<3>(v);      // error: valid index values are 0 and 1    try {      std::get<float>(w); // w contains int, not float: will throw    }    catch (const std::bad_variant_access&) {}    std::variant<std::string> x("abc"); // converting constructors work when unambiguous    x = "def"; // converting assignment also works when unambiguous    std::variant<std::string, bool> y("abc"); // holds *bool*, not std::string    assert(std::holds_alternative<bool>(y)); // succeeds    y = "xyz"s;    assert(std::holds_alternative<std::string>(y)); //succeeds   printf("Hello C++17\n");}

然后编译,执行,如下图则成功
这里写图片描述

接着是codeblock的配置

百度—>官网->找到ubuntu版本,链接点进去

这里写图片描述

执行它说的三个命令

这里写图片描述

下图的/usr 是gcc的默认目录。。然后,我们下载gcc选择的目录是usr/local/ 不过我们刚才已经通过
In命令映射了,所以通过/usr 能找到 gcc-7.1.0
这里写图片描述

这里写图片描述

此处很关键,setting->complier setting->other complier option里加上-std=c++17这句话
新建项目测试吧

官网下载eclipse for c/c++具体步骤类似:Window -> Preferences -> C/C++ -> Build -> Settings -> Discovery -> CDT GCC Build-in Compiler Settings在 Command to get compiler specs 加上 -std=c++14新建一个C++工程:For project created as: File -> New -> Project -> C/C++ -> C++ Project右击工程打开属性:Properties -> C/C++ Build -> Settings -> Tool Settings -> GCC C++ Compiler -> Dialect加上 -std=c++14 到 other dialect flags 

这里写图片描述

这里写图片描述

原创粉丝点击