在CDT项目中使用其他C ++编译器的正确方法是什么?

ein*_*ica 5 c++ eclipse-cdt version-compatibility eclipse-mars g++4.9

我在Linux上使用Eclipse CDT Mars.2(和Neon RC)。我的发行版的默认C ++编译器是GCC 5.3.1,但是对于我的某些工作,我使用GCC 4.9.3。我希望有关项目的所有内容都可以使用GCC 4.9.3:工具发现,C ++标准库,包含文件路径,索引器,预处理-全部。

什么是正确的方法?看来Eclipse具有相当拜占庭式的“提供者”和“工具链”配置,我不想进行设置,以后将无法撤消...

注意: 我确实尝试在某些Previous Includes等提供程序设置中替换${COMMAND}为 /usr/bin/g++-4.9,这确实导致发现了4.9.3相关的包含文件,但我的索引器并不喜欢这种方式,也不喜欢所有的std :: stuff显示为红色且未解决。然后,我尝试寻找在哪里设置用于索引的编译器版本,但找不到。

Jon*_*ham 4

有两个可能的答案,具体取决于您是进行“标准制作”还是“管理制作”。标准 Make 意味着您正在编写自己的 Makefile 并自己管理所有内容。Managed Make 意味着您让 CDT 创建 Makefile 并管理它们。

标准品牌

对于标准品牌,一切都由扫描仪发现的内容控制。扫描仪负责查找属于项目一部分的所有系统包含文件,并将这些文件输入索引器以解析符号,并且还允许头文件导航等操作。

要更改所使用的编译器,您需要替换${COMMAND}为您选择的编译器。您(作为用户)需要确保该命令与您在 Makefile 中使用的命令相匹配。

要更改${COMMAND}:

  1. 打开项目属性(右键单击项目)
  2. Select C/C++ General -> Preprocessor Include Paths, Macros, etc in the tree.
  3. Select Providers tab
  4. Select CDT GCC Built-in Compiler Settings from the list
  5. Replace the ${COMMAND} in Command to get compiler specs: to your desired g++ executable.

Here is a screenshot to help:

命令编辑

To see this in action, here are some screenshots with and without the change described. On my machine I have /usr/bin/g++ which is version 5.3 and /usr/bin/g++-4.7 which is version 4.7.

With default g++

克++5

With overridden g++ to version 4

克++4

Use Environment manage

The problem with the above is that you need to coordinate g++ between your Makefile and the build settings. One solution to this is to use the C/C++ Build Environment settings to define CXX as the compiler to use. Set the CXX environment variable in the project settings (Project Properties -> C/C++ Build -> Environment) or global preferences (Preferences -> C/C++ -> Build -> Environment).

Then replace ${COMMAND} with ${CXX}.

Here is a screenshot that demonstrates what I described:

环境

Managed Make

If, instead, you are using Managed Make, you need to override the build settings for the individual tools. These settings then feed into the Preprocessor Include Paths, Macros, etc. settings as used directly by Standard Make.

To change the build settings, you need to override the command used for the compiler in a few places, once for each type of tool. Start in Project Properties -> C/C++ Build -> Settings and then edit each of these:

  • GCC C++ Compiler -> Normally set to g++
  • GCC C 编译器-> 通常设置为gcc
  • GCC C++ 链接器-> 通常设置为g++

这是一个屏幕截图来演示:

管理制作截图