views:

139

answers:

4

Hello,

At my company we have recently done some tricky stuff with C++ and templates, making use of some features of the compiler. When working with this code people need to take a few setup steps otherwise they get some rather cryptic compiler errors, what I would like to do is determine if there is a way to tell the compiler to inject, and or swap out the message published for an error when compiling? so that I either get a friendly message that instructs the person in conjunction with the cryptic error or instead of the cryptic error.

Thank you.

+4  A: 

You have a couple of options, I think. First, you could use your build system and add a step to post-process the build output before showing it to the user; then you could detect and modify the error messages you care about. The other option, if you have access to your compiler's source code, is just to modify those strings in the compiler directly.

Carl Norum
A: 

Could you wrap the compiler in a script instead? The script would run the compiler and consume STDOUT/STDERR, and output user friendly messages instead.

Jeff B
This is the approach used by e.g. STLFilt. http://www.bdsoft.com/tools/stlfilt.html
Baffe Boyois
+1  A: 
gcc source.c 2>&1 | sed -e 's/Cryptic Message/Friendly Message/'

Mostly kidding. Adding post build step is probably better.

bde
+2  A: 

You should look into Static Assert.

dicroce