Eclipse CDT中构建结果与问题视图之间的差异 [英] discrepancy between build result and Problems view in Eclipse CDT

查看:70
本文介绍了Eclipse CDT中构建结果与问题视图之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Windows机器上使用带有CDT和MinGW工具链的Eclipse 4.2(尽管我觉得问题与该特定配置无关)。 G ++编译器为4.7

I'm using Eclipse 4.2, with CDT, and MinGW toolchain on a Windows machine (although I've a feeling the problem has nothing to do with this specific configuration). The G++ compiler is 4.7

我正在使用c ++ 11功能,并具有以下代码:

I'm playing with c++11 features, with the following code:

#include <iostream>
#include <iomanip>
#include <memory>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;

int main( int argc, char* argv[] )
{
    vector<int> v { 1, 2, 3, 4, 5, 6, 7 };
    int x {5};
    auto mark = remove_if( v.begin(), v.end(), [x](int n) { return n<x; } );
    v.erase( mark, v.end() );
    for( int x : v ) { cout << x << ", "; }
    cout << endl;
}

一切都是非常简单直接的c ++ 11。代码可以在命令行上毫无问题地编译(g ++ -std = c ++ 11 hello.cpp)。

为了使此代码得以编译在eclipse中,我将编译器设置为支持C + +11:

Everything is very straight forward and idiomatic c++11. The code compiles with no problems on the command line (g++ -std=c++11 hello.cpp).
In order to make this code compile In eclipse, I set the compiler to support C++11:


  1. 属性-> C / C ++构建->设置->杂项->其他标志:

    我要添加-std = c ++ 11

  2. 属性-> C / C ++ Build->发现选项->编译器调用参数:

    添加-std = c ++ 11

这是我对全局首选项或项目属性所做的唯一更改。

That's the only change I did to either the global preferences or to the project properties.

第一个问题:为什么我必须在两个地方更改标志?当使用每个编译器标志时?

First Question: Why do I've to change the flags in two places? When each compiler flags is used?

如果我按Ctrl-B,则项目将按预期成功构建,并在eclipse中运行,以显示预期结果(

If I hit Ctrl-B, the project will build successfully, as expected, and running it from within eclipse show the expected result (It prints: '5, 6, 7,').

但是,编辑器视图在 remove_if行和 v。行上均显示红色错误标记。删除行。同样,问题视图显示我有这两个问题。查看问题的详细信息,我得到:

However, the editor view shows red marks of error on both the 'remove_if' line, and the 'v.erase' line. Similarly, the Problems view shows I've these two problems. Looking at the details of the problem, I get:


  • 对于remove_if行:无效参数。候选者为:#0 remove_if(#0,#0,#1)

  • 对于擦除行:无效参数候选者为:?擦除(?),?擦除(?,?)'

第二个问题:似乎有两种不同的构建方式:一种用于继续状态,一个用于实际构建。那正确吗?如果是这样,它们是否具有不同的规则(编译标志,包含路径等)?

Second questions: It appears there are two different builds: one for continues status, and one for the actual build. Is that right? If so, do they have different rule (compilation flags, include paths, etc.)?

第三个问题:在问题详细信息中我还请参阅:索引器发现名称解析问题。我猜这就是为什么错误消息如此神秘的原因。这些消息是来自MinGW g ++编译器还是来自Eclipse?这是什么名称解析?我该如何解决?

Third question: In the problem details I also see: 'Name resolution problem found by the indexer'. I guess this is why the error message are so cryptic. Are those messages coming from MinGW g++ compiler or from Eclipse? What is this Name resolution? How do I fix?

感谢您的帮助。

编辑(回复@Eugene):谢谢尤金。我在Eclipse上打开了一个错误。我认为C ++ 11只是部分原因。我已经从C ++ 11内容中清除了代码,并从两个编译开关中都删除了-std = c ++ 11标志。然而,CodAn会在remove_if行上吠叫:

EDIT (in reply to @Eugene): Thank you Eugene. I've opened a bug on Eclipse. I think that C++11 is only partially to blame. I've cleaned my code from C++11 stuff, and removed the -std=c++11 flag from both compilation switch. And yet, the CodAn barks on the remove_if line:

int pred( int n ) { return n < 5; }

int main( int argc, char* argv[] )
{
    vector<int> v;
    for( int i=0; i<=7; ++i ) { 
        v.push_back( i );
    }

    vector<int>::iterator mark = remove_if( v.begin(), v.end(), pred );
    v.erase( mark, v.end() );

    for( vector<int>::iterator i = v.begin(); i != v.end(); ++i ) {
        cout << *i << ", ";
    }
    cout << endl;
}

代码可以很好地编译(使用Ctrl-B),但是CodAn不会t类似于remove_if行,说:无效的参数,候选者为'#0 remove_if(#0,#0,#1)'
这是一条非常含糊的消息-似乎错过了用格式字符串替换参数(#0代表迭代器,#1代表谓词)。我将更新该错误。

The code compiles just fine (with Ctrl-B), but CodAn doesn't like the remove_if line, saying: Invalid Arguments, Candidates are '#0 remove_if(#0,#0,#1)'. This is a very cryptic message - it appears it misses to substitute arguments in format string (#0 for 'iterator' and #1 for 'predicate'). I'm going to update the bug.

有趣的是,使用列表而不是向量可以清除错误。

Interestingly, using 'list' instead of 'vector' clears up the error.

但是,关于我的问题,我对CodAn的工作方式很好奇。它是否使用g ++(带有一组自定义标志)或其他外部工具(lint?),或者它是在Java内部完成的?如果有工具,我如何获取其命令行参数及其输出?

However, as for my question, I'm curious about how the CodAn work. Does it uses g++ (with a customized set of flags), or another external tool (lint?), or does it do it internally in Java? If there is a tool, how can I get its command line argument, and its output?

推荐答案


  1. Build / Settings-这些标志将包含在您的makefile中以进行实际的构建。构建/发现-当IDE发现扫描仪设置时,这些标志将传递给编译器。 IDE将在特殊模式下运行编译器,以发现预定义的宏的值,包含路径等。

我相信,您遇到的问题正在被 Codan检测到。 Codan是CDT编辑器中内置的静态分析,您可以在 C / C ++常规 /代码分析中找到其设置。如果您认为显示的错误是虚假的,则应将问题报告给bugs.eclipse.org。请注意,CDT尚不支持所有C ++ 11功能。

I believe, the problems you are seeing are detected by "Codan". Codan is a static analysis built into the CDT editor, you may find its settings on "C/C++ General"/"Code Analysis". You should report the problem to the bugs.eclipse.org if you feel the errors shown are bogus. Note that CDT does not yet support all C++11 features.

这篇关于Eclipse CDT中构建结果与问题视图之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆