Adam Hunyadi Adam Hunyadi - 14 days ago 5
C++ Question

Can I somehow filter the error message lines from gcc?

While coding in c++, I often get a really long error message for simple errors, such as mismatched parameters in function calls or parameter ambiguity. These error messages usually span through tens even hundreds of lines and it is pretty difficult to find where the actual error is.

Can someone tell me, if it is possible to do some manipulation on the output to find the error location "lazily"?

Im looking for something like:

make |& xclip_error_loc
... (make output)
(prints and/or adds this to the clipboard: sourcefile.cc:86:2)


It would be a really useful debugging tool can someone tell me how to achieve this?

Example compilation error:

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...)


Should output:

createClusterSizePairFrequencyValidationPlots.cc:167:62

Answer

To do this you can use grep.

The command would be like this

make 2>&1 | egrep ":[0-9]+:[0-9]+: error:"

This does two Things

  1. It moves stderr to stdout
  2. It looks for :"any number here":"any number": error: and prints out the corresponding line

So you should get only the lines with the information you want

When you add the -o option to egrep it should only print out what is matched so in our case it should only print

:123:456: error:

If you take the " error:" out of the egrep command you will only see numbers, but then you could get false matches so I would leave the " error:" in