简体   繁体   English

Eclipse CDT Oxygen:编译器问题

[英]Eclipse CDT Oxygen: Compiler issue

I'm running Ubuntu 16.04 and just opened my freshly installed Eclipse CDT Oxygen for the first time. 我正在运行Ubuntu 16.04,并且是第一次打开我刚安装的Eclipse CDT Oxygen。

I imported an existing C++ project that builds fine using a CMake file that sets add_definitions(-std=c++11) . 我导入了一个现有的C ++项目,该项目使用设置了add_definitions(-std=c++11)的CMake文件可以很好地构建。

I used CMake with the command cmake -G"Eclipse CDT4 - Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug ../src/ to generate Eclipse project files and then used those to import the project into Eclipse. 我将CMake与命令cmake -G"Eclipse CDT4 - Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug ../src/来生成Eclipse项目文件,然后使用这些文件将项目导入Eclipse。

Now I'm looking at a source file in my newly imported project inside Eclipse and see a ton of issues. 现在,我正在Eclipse中新导入的项目中查看源文件,并看到大量问题。 It's all types that cannot be resolved, for example std::default_random_engine . 所有无法解析的类型,例如std::default_random_engine

My guess is that Eclipse doesn't have the right toolchain configured. 我的猜测是Eclipse没有配置正确的工具链。

I have a few questions: 我有几个问题:

  1. How can I see the toolchain for my project and how can I change it? 如何查看项目的工具链,以及如何更改它? I looked up this help article, but the sections in the project properties menu I see are not the same as in the help article. 我查找了帮助文章,但是我看到的项目属性菜单中的部分与帮助文章中的部分不同。 The project properties menu I see does not have a "C/C++ Build" section. 我看到的项目属性菜单没有“ C / C ++构建”部分。 How can that be? 怎么可能?

  2. The CMake file that I used to generate the Eclipse project files specifies that C++11 is supposed to be used, so why isn't this the case then? 我用来生成Eclipse项目文件的CMake文件指定应该使用C ++ 11,那么为什么不这样呢?

Here is what my project properties menu looks like: 这是我的项目属性菜单的样子:

在此处输入图片说明

This is what my .project file looks like: 这是我的.project文件的样子:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>particle_filter</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
            <triggers>clean,full,incremental,</triggers>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
            <triggers>full,incremental,</triggers>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.cdt.core.cnature</nature>
        <nature>org.eclipse.cdt.core.ccnature</nature>
        <nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
        <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
    </natures>
</projectDescription>

Thanks a lot! 非常感谢!

The missing C/C++ Build section can be caused by a broken .project , .cproject or .settings/language.settings.xml file: 缺少的C / C ++构建部分可能是由于损坏的.project.cproject.settings/language.settings.xml文件引起的:

  1. Create a new project of the same type 创建一个相同类型的新项目
  2. In the Navigator view compare the .project , the .cproject and the .settings/language.settings.xml files with the corresponding files of the new project to find the problem (make sure to use same IDs in .cproject and in .settings/language.settings.xml , but different IDs than in other projects) 在“ 导航器”视图中, .project.cproject.settings/language.settings.xml文件 新项目的相应文件进行比较,以发现问题(确保在.cproject.settings/language.settings.xml使用相同的ID .settings/language.settings.xml ,但ID与其他项目不同)

I think CMake's CDT project generator is fairly out of date and doesn't configure the generated project properly for C++11 support. 我认为CMake的CDT项目生成器已经过时,并且没有为C ++ 11支持正确配置生成的项目。

I recommend the following approach for configuring C++11 support: 我建议采用以下方法来配置C ++ 11支持:

  • Go to Project Properties | C/C++ General | Preprocessor Include Paths 转到Project Properties | C/C++ General | Preprocessor Include Paths Project Properties | C/C++ General | Preprocessor Include Paths Project Properties | C/C++ General | Preprocessor Include Paths . Project Properties | C/C++ General | Preprocessor Include Paths
  • In the Providers tab, select CDT GCC Built-in Compiler Settings . Providers标签中,选择CDT GCC Built-in Compiler Settings
  • (If necessary, uncheck "Use global provider shared between projects".) (如有必要,请取消选中“使用项目之间共享的全局提供程序”。)
  • Add -std=c++11 to the "Command to get compiler specs". -std=c++11添加到“获取编译器规范的命令”中。
  • Apply and rebuild the project's index. 应用并重建项目的索引。

After doing this, C++11 symbols should be resolved properly. 完成此操作后,应正确解析C ++ 11符号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM