C++ 使用带有 minGW 的 Eclipse 的多个“无法解决”问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21065616/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 23:27:47  来源:igfitidea点击:

Multiple "could not be resolved" problems using Eclipse with minGW

c++eclipsegccc++11mingw32

提问by Jim

I have recently installed (the latest builds of) 'Eclipse IDE for C/C++ Developers' and minGW (4.8.1) to help me to get back into C++ after a long time away.

我最近安装了(最新版本)'Eclipse IDE for C/C++ Developers' 和 minGW (4.8.1) 以帮助我在很长一段时间后重新使用 C++。

I have added -std=c++11to Other flagsat C/C++ Build/Settings/Tool Settings/GCC C++ Compiler/Miscellaneous

我已经加入-std=c++11Other flagsC/C++ Build/Settings/Tool Settings/GCC C++ Compiler/Miscellaneous

I have a small program utilizing a number of C++11 features (e.g. using the chronolibrary, .emplace_back).

我有一个使用许多 C++11 特性的小程序(例如使用chrono库,.emplace_back)。

After Run I get multiple unresolved issues in the Problems window, as Pasted below).

运行后,我在“问题”窗口中遇到多个未解决的问题,如下所示)。

Interestingly, the program does compile and run ok.

有趣的是,该程序确实编译并运行正常。

  1. With this, is there something I'm not setting up in Eclipse to resolve these issues?

  2. Does anyone know if there still an issue with the to_string()function in minGW (4.8.1) e.g. the following does not compile:

    window.setTitle("Bullets on screen: " + to_string(bullets.size()) + " currentSlice: " + to_string(currentSlice) + " FT: " + to_string(ft) + " FPS: " + to_string(fps) );
    

    It does compile using Visual Studio Express 2013 (though it has an issue with the accuracy of the chronolibrary, hence the switch to minGW).

    Thanks.

  1. 有了这个,我没有在 Eclipse 中设置一些东西来解决这些问题吗?

  2. 有谁知道to_string()minGW(4.8.1)中的函数是否仍然存在问题,例如以下不能编译:

    window.setTitle("Bullets on screen: " + to_string(bullets.size()) + " currentSlice: " + to_string(currentSlice) + " FT: " + to_string(ft) + " FPS: " + to_string(fps) );
    

    它确实使用 Visual Studio Express 2013 进行编译(尽管它在chrono库的准确性方面存在问题,因此切换到 minGW)。

    谢谢。

Eclipse 'Problem' window output:

Eclipse“问题”窗口输出:

Description Resource Path Location Type
 Symbol 'duration' could not be resolved chronotest.cpp /chronotest/src line 19 Semantic Error
 Function 'now' could not be resolved Test2.cpp /Test2/src line 143 Semantic Error
 Function 'duration_cast' could not be resolved Test2.cpp /Test2/src line 160 Semantic Error
 Function 'now' could not be resolved Test2.cpp /Test2/src line 158 Semantic Error
 Symbol 'chrono' could not be resolved Test2.cpp /Test2/src line 8 Semantic Error
 Type 'std::centi' could not be resolved chronotest.cpp /chronotest/src line 20 Semantic Error
 Type 'std::chrono::seconds' could not be resolved chronotest.cpp /chronotest/src line 24 Semantic Error
 Type 'std::time_t' could not be resolved chronotest.cpp /chronotest/src line 48 Semantic Error
 Symbol 'duration' could not be resolved chronotest.cpp /chronotest/src line 47 Semantic Error
 Function 'now' could not be resolved chronotest.cpp /chronotest/src line 44 Semantic Error
 Function 'now' could not be resolved chronotest.cpp /chronotest/src line 39 Semantic Error
 Type 'std::chrono::system_clock' could not be resolved chronotest.cpp /chronotest/src line 38 Semantic Error
 Function 'end' could not be resolved Test2.cpp /Test2/src line 214 Semantic Error
 Symbol 'time_point' could not be resolved chronotest.cpp /chronotest/src line 38 Semantic Error
 Function 'end' could not be resolved Test2.cpp /Test2/src line 212 Semantic Error
 Type 'milli' could not be resolved Test2.cpp /Test2/src line 161 Semantic Error
 Method 'count' could not be resolved Test2.cpp /Test2/src line 161 Semantic Error
 Symbol 'duration_cast' could not be resolved Test2.cpp /Test2/src line 160 Semantic Error
 Symbol 'duration' could not be resolved Test2.cpp /Test2/src line 161 Semantic Error
 Method 'count' could not be resolved chronotest.cpp /chronotest/src line 51 Semantic Error
 Symbol 'duration_cast' could not be resolved chronotest.cpp /chronotest/src line 30 Semantic Error
 Method 'count' could not be resolved chronotest.cpp /chronotest/src line 30 Semantic Error
 Function 'to_time_t' could not be resolved chronotest.cpp /chronotest/src line 48 Semantic Error
 Method 'count' could not be resolved chronotest.cpp /chronotest/src line 32 Semantic Error
 Function 'ctime' could not be resolved chronotest.cpp /chronotest/src line 50 Semantic Error
 Method 'count' could not be resolved chronotest.cpp /chronotest/src line 33 Semantic Error
 Symbol 'duration' could not be resolved chronotest.cpp /chronotest/src line 22 Semantic Error
 Invalid arguments '
 Candidates are:
 __gnu_cxx::__normal_iterator<Bullet *,std::vector<Bullet,std::allocator<Bullet>>> erase(__gnu_cxx::__normal_iterator<Bullet *,std::vector<Bullet,std::allocator<Bullet>>>)
 __gnu_cxx::__normal_iterator<Bullet *,std::vector<Bullet,std::allocator<Bullet>>> erase(__gnu_cxx::__normal_iterator<Bullet *,std::vector<Bullet,std::allocator<Bullet>>>, __gnu_cxx::__normal_iterator<Bullet *,std::vector<Bullet,std::allocator<Bullet>>>)
 ' Test2.cpp /Test2/src line 212 Semantic Error
 Symbol 'ratio' could not be resolved chronotest.cpp /chronotest/src line 22 Semantic Error
 Invalid arguments '
 Candidates are:
 #0 remove_if(#0, #0, #1)
 ' Test2.cpp /Test2/src line 212 Semantic Error
 Symbol 'duration_cast' could not be resolved chronotest.cpp /chronotest/src line 28 Semantic Error
 Method 'count' could not be resolved chronotest.cpp /chronotest/src line 28 Semantic Error
 Method 'emplace_back' could not be resolved Test2.cpp /Test2/src line 191 Semantic Error
 Symbol 'ratio' could not be resolved chronotest.cpp /chronotest/src line 19 Semantic Error
 Symbol 'duration' could not be resolved chronotest.cpp /chronotest/src line 20 Semantic Error
 Symbol 'duration' could not be resolved chronotest.cpp /chronotest/src line 21 Semantic Error
 Function 'begin' could not be resolved Test2.cpp /Test2/src line 212 Semantic Error
 Symbol 'ratio' could not be resolved chronotest.cpp /chronotest/src line 21 Semantic Error


[Edit]: Apologies for not including error details for the remaining "to_string". The Eclipse 'Problem' window output has the following:

[编辑]:抱歉没有包含剩余“to_string”的错误详细信息。Eclipse“问题”窗口输出如下:

    Description Resource    Path    Location    Type
'to_string' was not declared in this scope  Test2.cpp   /Test2/src  line 170    C/C++ Problem
Function 'to_string' could not be resolved  Test2.cpp   /Test2/src  line 170    Semantic Error
Function 'to_string' could not be resolved  Test2.cpp   /Test2/src  line 170    Semantic Error
unused variable 'currentSlice' [-Wunused-variable]  Test2.cpp   /Test2/src  line 125    C/C++ Problem
Function 'to_string' could not be resolved  Test2.cpp   /Test2/src  line 170    Semantic Error
Invalid arguments '
Candidates are:
void setTitle(const sf::String &)
'   Test2.cpp   /Test2/src  line 170    Semantic Error
Function 'to_string' could not be resolved  Test2.cpp   /Test2/src  line 170    Semantic Error

回答by Nabla

Go to Project -> Properties -> C/C++ General -> Preprocessor Include Paths, Macros, etc. -> Providers -> CDT GCC built-in compiler settings, deactivate Use global provider shared between projectsand add the command line argument -std=c++11.

转到Project -> Properties -> C/C++ General -> Preprocessor Include Paths, Macros, etc. -> Providers -> CDT GCC built-in compiler settings,停用Use global provider shared between projects并添加命令行参数-std=c++11

The eclipse live code analysis does not share the same settings with the build compiler. You can also change the setting globally (not just for the project) in Window -> Preferences -> C/C++ -> Build -> Settings -> CDT GCC Built-in Compiler Settings.

eclipse 实时代码分析与构建编译器不共享相同的设置。您还可以在Window -> Preferences -> C/C++ -> Build -> Settings -> CDT GCC Built-in Compiler Settings.

Edit: You need to #include <string>to use std::to_string.

编辑:您需要#include <string>使用std::to_string.

回答by Jim

I'm adding a few details to the answers given by @Nabla and @Enissey.

我正在为@Nabla 和@Enissey 给出的答案添加一些细节。

When adding the command line argument, for example, CDT GCC Built-in Compiler Settings Cygwin in Global preferences,

添加命令行参数时,例如,全局首选项中的 CDT GCC 内置编译器设置 Cygwin,

${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"

do it like so,

这样做,

${COMMAND} ${FLAGS} -E -P -v -dD -std=c++11 "${INPUTS}"

To rebuild the index, right-click on your project, go under the Index sub-menu, and choose "Rebuild."

重建索引,请右键单击您的项目,进入索引子菜单,然后选择“重建”。

In my case, I made the changes globally and rebuilt the index.

就我而言,我进行了全局更改并重建了索引。

回答by USer22999299

Re download the gcccompiler from:

gcc从以下位置重新下载编译器:

http://www.equation.com/servlet/equation.cmd?fa=fortran

install it in c:\minGWfolder use new worksapce / fresh eclipse setting , it work like a charm!

c:\minGW使用新的工作空间/新的 eclipse 设置将其安装在文件夹中,它就像一个魅力!

Don't forget to restart before trying , re build and set etc.

在尝试之前不要忘记重新启动,重新构建和设置等。

as well to set MinGWas a default tool chain windows -> preferences -> New C++.. ->set MinMGas a tool chain preferred.

以及设置MinGW为默认工具链 windows -> 首选项 -> 新 C++.. -> 设置MinMG为首选工具链。

If you cannot see it on the list , deselect the "show project types...." as well when creating the project.

如果在列表中看不到它,请在创建项目时取消选择“显示项目类型....”。