eclipse 构造 C++ 11 -- ubuntu 12.04

时间:2025-02-07 13:36:14

设备g++ 4.8

sudo apt-get install python-software-properties

sudo add-apt-repository ppa:ubuntu-toolchain-r/test

sudo apt-get update

sudo apt-get install g++-4.8

sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50

最后看看 g++ 的版本,看是否成功安装
g++ --version

安装 gdb 7.7

Ubuntu 12.4 自带的 gdb 版本号为 7.4, 当升级 gcc 到 4.8 后, 会导致 gdb 与 gcc 不兼容, 通常会报 "符号表找不到"或"Missing separate debuginfos, use: debuginfo-install glib" 这种错误, 将 gdb 升级到 7.7 就可以解决.



我眼下尚未找到有效的源。通过简单的 apt-get install gdb 来升级 gdb 到 7.7, 所以仅仅能进行手动安装.



1 在这里下载最新版本号 gdb 的 tar 包, 当前最新版本号为 7.7.1, 所下面载 gdb-7.7.1.tar.bz2 就可以. http://www.sourceware.org/gdb/

2 解压上面下载的文件, 默认解压出来的目录名字为 gdb-7.7.1.

3用terminal 进入到 gdb-7.7.1, 顺序运行下面 3 个命令(./configure 会生成 make 文件), 就可以安装成功.
$ ./configure

$ make

$ sudo make install
4 假设安装时报错: no termcap library found; 则需安装相关依赖程序

sudo apt-get install texinfo libncurses5-dev

配置全局的编译參数:

选中eclipse工具栏 Project -> Properties -> C/C++ Build -> Settings -> Miscellaneous. 在右边的 Other flags 加入 -std=c++11
假设仅仅是针对某个project,则右键选中 目标project-> Properties -> C/C++ Build -> Settings -> Miscellaneous. 在右边的 Other flags 加入 -std=c++11

配置eclipse CDT 的 indexer。

方便编辑器正确的解析C++11的keyword、符号等。

选中eclipse工具栏 Project -> Properties->C/C++ General -> Preprocessor Include Paths, Macros etc.:

  1. 选择标签页“Providers”
  2. Configuration栏选择Debug(之后还可配置“Release”)
  3. 在标签页“Providers”下选中"CDT GCC Built-in Compiler Settings"。
  4. 反勾选 Use global provider shared between projects.
  5. 在Command to get compiler specs栏后面加入 "-std=c++11" (不带引號);
  6. 最后选则apply 和 OK。
  7. 最后又一次build C/C++ 的 indexer. Project -> C/C++ Index -> Rebuild.

參考文章

版权声明:本文博主原创文章,博客,未经同意不得转载。