What's the right way to work with a different C++ compiler in a CDT project?

江枫思渺然 提交于 2019-12-05 08:32:31

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.

Standard Make

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.

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.

To change the ${COMMAND}:

  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:

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++

With overridden g++ to version 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 Compiler -> Normally set to gcc
  • GCC C++ Linker -> Normally set to g++

Here is a screenshot to demonstrate:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!