首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我能以某种方式过滤GCC的错误信息吗?

我能以某种方式过滤GCC的错误信息吗?
EN

Stack Overflow用户
提问于 2016-11-23 13:39:22
回答 1查看 176关注 0票数 0

在C++中编写代码时,对于简单的错误,比如函数调用中的参数不匹配或参数的歧义,我通常会收到一条非常长的错误消息。这些错误消息通常跨越几十行甚至数百行,很难找到实际的错误所在。

是否可以对输出进行一些操作以“懒惰”地找到错误位置?

我在找这样的东西:

代码语言:javascript
复制
make |& xclip_error_loc
... (make output)
(prints and/or adds this to the clipboard: sourcefile.cc:86:2)

这将是一个非常有用的调试工具。我怎样才能做到这一点?

示例编译错误:

代码语言:javascript
复制
Compiling test: "createClusterSizePairFrequencyValidationPlots"...
src/createClusterSizePairFrequencyValidationPlots.cc: In function 'int main(int, char**)':
src/createClusterSizePairFrequencyValidationPlots.cc:167:62: error: no matching function for call to 'TH2I::Fill(const int&, const float&, const char [2])'
 ngthYVsPhi_H  .Fill(cluster.sizeY,       phi, "1");
                                                  ^
In file included from /cvmfs/cms.cern.ch/slc6_amd64_gcc530/cms/cmssw/CMSSW_8_0_18/external/slc6_amd64_gcc530/bin/../../../../../../lcg/root/6.06.00-ikhhed4/include/TH2D.h:25:0,
                 from src/../interface/ClusterPairFunctions.h:7,
                 from src/createClusterSizePairFrequencyValidationPlots.cc:8:
/cvmfs/cms.cern.ch/slc6_amd64_gcc530/cms/cmssw/CMSSW_8_0_18/external/slc6_amd64_gcc530/bin/../../../../../../lcg/root/6.06.00-ikhhed4/include/TH2.h:63:13: note: candidate: virtual Int_t TH2::Fill(Double_t)
    Int_t    Fill(Double_t); //MayNotUse
             ^
/cvmfs/cms.cern.ch/slc6_amd64_gcc530/cms/cmssw/CMSSW_8_0_18/external/slc6_amd64_gcc530/bin/../../../../../../lcg/root/6.06.00-ikhhed4/include/TH2.h:63:13: note:   candidate expects 1 argument, 3 provided
/cvmfs/cms.cern.ch/slc6_amd64_gcc530/cms/cmssw/CMSSW_8_0_18/external/slc6_amd64_gcc530/bin/../../../../../../lcg/root/6.06.00-ikhhed4/include/TH2.h:64:13: note: candidate: virtual Int_t TH2::Fill(const char*, Double_t)
    Int_t    Fill(const char*, Double_t) { return Fi
             ^
/cvmfs/cms.cern.ch/slc6_amd64_gcc530/cms/cmssw/CMSSW_8_0_18/external/slc6_amd64_gcc530/bin/../../../../../../lcg/root/6.06.00-ikhhed4/include/TH2.h:64:13: note:   candidate expects 2 arguments, 3 provided
/cvmfs/cms.cern.ch/slc6_amd64_gcc530/cms/cmssw/CMSSW_8_0_18/external/slc6_amd64_gcc530/bin/../../../../../../lcg/root/6.06.00-ikhhed4/include/TH2.h:75:21: note: candidate: virtual Int_t TH2::Fill(Double_t, Double_t)
    virtual Int_t    Fill(Double_t x, Double_t y);
                     ^
/cvmfs/cms.cern.ch/slc6_amd64_gcc530/cms/cmssw/CMSSW_8_0_18/external/slc6_amd64_gcc530/bin/../../../../../../lcg/root/6.06.00-ikhhed4/include/TH2.h:75:21: note:   candidate expects 2 arguments, 3 provided
/cvmfs/cms.cern.ch/slc6_amd64_gcc530/cms/cmssw/CMSSW_8_0_18/external/slc6_amd64_gcc530/bin/../../../../../../lcg/root/6.06.00-ikhhed4/include/TH2.h:76:21: note: candidate: virtual Int_t TH2::Fill(Double_t, Double_t, Double_t)
    virtual Int_t    Fill(Double_t x, Double_t y, Do
                     ^
/cvmfs/cms.cern.ch/slc6_amd64_gcc530/cms/cmssw/CMSSW_8_0_18/external/slc6_amd64_gcc530/bin/../../../../../../lcg/root/6.06.00-ikhhed4/include/TH2.h:76:21: note:   no known conversion for argument 3 from 'const char [2]' to 'Double_t {aka double}'
/cvmfs/cms.cern.ch/slc6_amd64_gcc530/cms/cmssw/CMSSW_8_0_18/external/slc6_amd64_gcc530/bin/../../../../../../lcg/root/6.06.00-ikhhed4/include/TH2.h:77:21: note: candidate: virtual Int_t TH2::Fill(Double_t, const char*, Double_t)
    virtual Int_t    Fill(Double_t x, const char *na
                     ^
/cvmfs/cms.cern.ch/slc6_amd64_gcc530/cms/cmssw/CMSSW_8_0_18/external/slc6_amd64_gcc530/bin/../../../../../../lcg/root/6.06.00-ikhhed4/include/TH2.h:77:21: note:   no known conversion for argument 2 from 'const float' to 'const char*'
/cvmfs/cms.cern.ch/slc6_amd64_gcc530/cms/cmssw/CMSSW_8_0_18/external/slc6_amd64_gcc530/bin/../../../../../../lcg/root/6.06.00-ikhhed4/include/TH2.h:78:21: note: candidate: virtual Int_t TH2::Fill(const char*, Double_t, Double_t)
    virtual Int_t    Fill(const char *namex, Double_
                     ^
/cvmfs/cms.cern.ch/slc6_amd64_gcc530/cms/cmssw/CMSSW_8_0_18/external/slc6_amd64_gcc530/bin/../../../../../../lcg/root/6.06.00-ikhhed4/include/TH2.h:78:21: note:   no known conversion for argument 3 from 'const char [2]' to 'Double_t {aka double}'
/cvmfs/cms.cern.ch/slc6_amd64_gcc530/cms/cmssw/CMSSW_8_0_18/external/slc6_amd64_gcc530/bin/../../../../../../lcg/root/6.06.00-ikhhed4/include/TH2.h:79:21: note: candidate: virtual Int_t TH2::Fill(const char*, const char*, Double_t)
    virtual Int_t    Fill(const char *namex, const c
                     ^
(lots of similar lines...)

它应产出:

createClusterSizePairFrequencyValidationPlots.cc:167:62

更新到NIoSaT:的答案

要复制错误消息,请执行以下操作:

代码语言:javascript
复制
make 2>&1 | egrep -o ":[0-9]+:[0-9]+: error" | xargs echo -n | xclip -selection clipboard && xclip -selection clipboard -o && echo ""

仅复制和显示第一个错误:

代码语言:javascript
复制
make 2>&1 | egrep -o ":[0-9]+:[0-9]+: error" | head -n 1 | xargs echo -n | xclip -selection clipboard && xclip -selection clipboard -o && echo ""
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-23 14:01:29

要做到这一点,您可以使用grep。

命令应该是这样的

代码语言:javascript
复制
make 2>&1 | egrep ":[0-9]+:[0-9]+: error:"

这做了两件事

  1. 它将stderr移动到stdout。
  2. 它查找:“这里的任意数字”:“任意数字”:error:并打印出相应的行。

所以你应该只得到你想要的信息

更新答案:

若要复制错误消息,请执行以下操作:

代码语言:javascript
复制
make 2>&1 | egrep -o ":[0-9]+:[0-9]+: error" | xargs echo -n | xclip -selection clipboard && xclip -selection clipboard -o && echo ""

仅复制和显示第一个错误:

代码语言:javascript
复制
make 2>&1 | egrep -o ":[0-9]+:[0-9]+: error" | head -n 1 | xargs echo -n | xclip -selection clipboard && xclip -selection clipboard -o && echo ""
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40766042

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档