在C ++编码时,我经常会收到一个非常长的错误消息,表示简单错误,例如函数调用中的参数不匹配或参数模糊。这些错误消息通常跨越几十甚至几百行,并且很难找到实际错误的位置。
是否可以对输出进行一些操作以找到错误位置"懒洋洋地"?
我正在寻找类似的东西:
make |& xclip_error_loc
... (make output)
(prints and/or adds this to the clipboard: sourcefile.cc:86:2)
这将是一个非常有用的调试工具。我如何实现这一目标?
编译错误示例:
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的答案:
要复制错误消息:
make 2>&1 | egrep -o ":[0-9]+:[0-9]+: error" | xargs echo -n | xclip -selection clipboard && xclip -selection clipboard -o && echo ""
复制并仅显示第一个错误:
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 :(得分:0)
要执行此操作,您可以使用grep。
命令就像这样
make 2>&1 | egrep ":[0-9]+:[0-9]+: error:"
这有两件事
因此,您应该只获得包含所需信息的行
更新答案:
复制错误消息:
make 2>&1 | egrep -o ":[0-9]+:[0-9]+: error" | xargs echo -n | xclip -selection clipboard && xclip -selection clipboard -o && echo ""
复制并仅显示第一个错误:
make 2>&1 | egrep -o ":[0-9]+:[0-9]+: error" | head -n 1 | xargs echo -n | xclip -selection clipboard && xclip -selection clipboard -o && echo ""