Igor
Igor

Reputation: 6285

Eclipse - set the C++ standard

ALL,

I'm worjking under RHEL 8 with the latest (2021-09) Eclipse version 4.21.0.

I'd like to set a C++ standard to be c++11, since I need a compatibility with the RHEL7.

I tried to follow instructyion I found on a different SO questions but none was sufficient, since many options were removed in this latest Eclipse version.

Could someone please give me a way to set it up for the latest Eclipse release, please?

TIA!!

Upvotes: 1

Views: 1901

Answers (1)

Dan
Dan

Reputation: 21

Here's what worked for me on Eclipse CDT 2024-06. I was using C99, but I don't expect any differences for C11. I previously used Option 2/3, but reading some of the comments lead me to Option 1, which is my preference now. The advantage of Option 2/3 is that it is less restrictive than Option 1, which (on my installation at least) only allows choosing C90, C99 and C11

Option 1 using CDT Internal Builder:

  1. Go to Project->Properties
  2. Within the properties menu, go to C/C++ Build->Tool Chain Editor
  3. Uncheck Display compatible toolchains only
  4. Set the "Current Toolchain" to Linux GCC
  5. Set the "Current Builder" to CDT Internal Builder
  6. Click the Apply and Close button in the bottom right (This is important! The necessary tabs will be missing if the menu is not closed)
  7. Go to Project->Properties again
  8. Within the properties menu, go to C/C++ Build->Settings
  9. Click on the Tool Settings tab within the settings window
  10. Go to GCC C Compiler->Dialect within the tab
  11. Set the "Language standard" to ISO C11 (-std=c11)
  12. Click the "Apply and Close" button in the bottom right again

Option 2 adjusting the Built-in Compiler Settings per project:

  1. Go to Project->Properties
  2. Within the properties menu, go to C/C++ General->Preprocessor Include Paths, Macros etc.
  3. Click on the Providers tab
  4. Check the CDT GCC Built-in Compiler Settings option if it is unchecked, and select it otherwise (Cygwin or MinGW suffix may be required depending on the installation, I cannot say for sure though)
  5. In the text box under "Command to get compiler specs:", add -std=c11 as an argument before "${INPUTS}" (Assuming this was previously unchanged, the text should now be ${COMMAND} ${FLAGS} -E -P -v -dD -std=c11 "${INPUTS}"
  6. Click the Apply and Close button in the bottom right

Option 3 using the default Built-in Compiler Settings:

  1. Go to Window->Preferences
  2. Within the preferences menu, go to C/C++->Build->Settings
  3. Click on the Discovery tab within the settings window
  4. Click on CDT GCC Built-in Compiler Settings (Again, the Cygwin/MinGW suffix may be required depending on installation)
  5. In the text box under "Command to get compiler specs:", add -std=c11 as an argument before "${INPUTS}" (Assuming this was previously unchanged, the text should now be ${COMMAND} ${FLAGS} -E -P -v -dD -std=c11 "${INPUTS}"
  6. Click the Apply and Close button in the bottom right

Now the global default is setup, this is all you need to do for each project:

  1. Go to Project->Properties
  2. Within the properties menu, go to C/C++ General->Preprocessor Include Paths, Macros etc.
  3. Click on the Providers tab
  4. Check the CDT GCC Built-in Compiler Settings option if it is unchecked, and select it otherwise (Again, the Cygwin/MinGW suffix may be required depending on installation)
  5. Check the "Use global provider shared between projects" option below the list
  6. Click the Apply and Close button in the bottom right

Upvotes: 0

Related Questions