Eclipse indexer proper c++11 syntax highlighting when generating projects with cmake

前端 未结 3 1374
不知归路
不知归路 2021-02-05 18:50

I know you can enable proper syntax highlighting with the GXX_EXPERIMENTAL hack described here: Eclipse CDT indexer does not know C++11 containers

But i think, when gene

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-05 19:31

    The answer is pretty simple.

    The eclipse cdt generator ignores the definitions added with add_definitions(...) when parsing the symbols. Instead it uses the CMAKE_CXX_COMPILER_ARG1. So all you have to do is: Add -DCMAKE_CXX_COMPILER_ARG1=-std=c++11 when invoking cmake

    Generating project files from commandline:

    cmake ../../src -G"Eclipse CDT4 - MinGW Makefiles" -DCMAKE_ECLIPSE_VERSION=4.2 -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER_ARG1=-std=c++11
    

    Generating projects from cmake gui:

    - Select source and build directory.
    - now BEFORE hitting configure or generate. Press "Add Entry" and add a new entry. Name:CMAKE_CXX_COMPILER_ARG1 Type:STRING Value:-std=c++11
    - press Generate and create the Eclipse project
    

    It is important to set the CMAKE_CXX_COMPILER_ARG1 upfront before hitting configure or generate the first time!

    That´s it. The project will be generated with correct symbols. indexer, syntax highlighting and autocompletion should work as intended without changing any project settings by hand.

提交回复
热议问题