在CDT项目中使用其他C ++编译器的正确方法是什么? [英] What's the right way to work with a different C++ compiler in a CDT project?

查看:123
本文介绍了在CDT项目中使用其他C ++编译器的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I use Eclipse CDT Mars.2 (and Neon RC), on Linux. My distribution's default C++ compiler is GCC 5.3.1, but for some of my work I use GCC 4.9.3. I would like everything regarding my project to use GCC 4.9.3: The tool discovery, the C++ standard library, the include file paths, the indexer, the preprocessing - all of it.

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

What's the right way to do this? It seems Eclipse has rather byzantine "providers" and "toolchains" configurations and I do not want to make settings I won't be able to undo later...

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

Note: I did try to replace ${COMMAND} with /usr/bin/g++-4.9 in some of the Preprocessor Includes etc. provider settings, and this did result in 4.9.3-related include files being discovered, but my indexer didn't like that and all of the std::stuff showed up red and unresolved. Then I tried looking for where I set the compiler version used for indexing but I couldn't find that.

推荐答案

有两种可能的答案,具体取决于您要执行的是标准制作"还是损坏的制作". Standard Make意味着您正在编写自己的Makefile并管理所有内容. Managed Make意味着您要让CDT创建Makefile并对其进行管理.

There are two possible answers, depending on whether you are doing "Standard Make" or "Mangaged Make". Standard Make means you are writing your own Makefiles and managing all that yourself. Managed Make means you are letting CDT create the Makefiles and manage them.

对于标准配置,一切都由扫描仪发现的内容控制.扫描程序可以查找项目中所有系统包含的文件,并将这些文件馈入索引器以解析符号,还可以进行头文件导航之类的操作.

For standard make, everything is controlled by what the scanner discovers. The scanner handles finding all the system include files that are part of your project, and those are fed into the indexer to resolve symbols and also allows things like header file navigation.

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

To change the compiler that is used, you need replace ${COMMAND} with your compiler of choice. It is up to you (as the user) to ensure that this command matches what you are using in your Makefile.

要更改${COMMAND}:

  1. 打开项目属性(通过右键单击项目)
  2. 在树中选择 C/C ++ General -> 预处理器包含路径,宏等.
  3. 选择提供商标签
  4. 从列表中选择 CDT GCC内置编译器设置
  5. 命令中的${COMMAND}替换为所需的g ++可执行文件以获取编译器规范:.
  1. Open Project Properties (by right-clicking on the project)
  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:

要查看实际操作,以下是一些屏幕快照,其中包含或不包含所描述的更改.在我的计算机上,我有5.3版的/usr/bin/g++和4.7版的/usr/bin/g++-4.7.

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.

使用默认的g ++

将g ++覆盖到版本4

上述问题是您需要在Makefile和构建设置之间协调 g ++ .一种解决方案是使用 C/C ++构建环境设置将CXX定义为要使用的编译器.在项目设置(项目属性-> C/C ++ Build -> 环境)或全局首选项(<首选项-> C/C ++ -> 构建-> 环境).

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).

然后将${COMMAND}替换为${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.

要更改构建设置,您需要在几个地方覆盖用于编译器的命令,每种类型的工具应覆盖一次.从项目属性-> C/C ++构建-> 设置开始,然后编辑以下各项:

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 ++编译器->通常设置为g++
  • GCC C编译器->通常设置为gcc
  • GCC C ++链接器->通常设置为g++
  • GCC C++ Compiler -> Normally set to g++
  • GCC C Compiler -> Normally set to gcc
  • GCC C++ Linker -> Normally set to g++

这是演示的屏幕截图:

这篇关于在CDT项目中使用其他C ++编译器的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆