Sunday, January 30, 2022

Installing C++17 on CentOS 7 and using it with Eclipse

By default, CentOS 7 supports C++ up to 2011 (C++11). For C++17 (2017) support with Eclipse IDE:
  1. Login to CentoOS 7 as root.
  2. Open terminal.
  3. Install Developer Toolset 8yum install dev-toolset-8
  4. cd into Eclipse folder.
  5. Enable toolset 8 for Eclipse and open it: scl enable devtoolset-8 ./eclipse
  6. After Eclipse opens, open/create a C++ project, use this filesystem example.
  7. Go to project properties - C/C++ Build - Settings - Tool Settings - GCC C++ Compiler -  Dialect - Other dialect flags and enter -std=c++17:
  8. Now you can build your project using C++ 2017 features. If you print __cplusplus, you get 201703. Note that project include folders point to devtoolset-8:

Rebuild index. Now you can compile but still get linker error.

Add linker flag -lstdc++fs and reorder linker flags so that -lstdc++fs is at the end: ${COMMAND} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS} ${FLAGS}

Now you can successfully run the example.

No comments:

Post a Comment