Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

(This is not a question about a compile error, but about the Linux terminal setting.)

During any compile error, the error statement doesn't properly display code fragments:

In member function â:
error: â was not declared in this scope

Is there a setting to get my terminal to properly show:

In member function `foo()':
error: `endl' was not declared in this scope

More info: This shows-up in Emacs compile mode correctly, but even saving that buffer to a temporary file and reading it on the command-line produces the above characters. Reading that file in Vim shows that the strange characters represent more than one column of text.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

I think you should first check the locale settings with:

locale

If it is not aligned with the character set of the file then you might be getting errors, as such.

file yoursrcfile

should provide you with the necessary information.

There is the case also that your compiler is running with a different locale. You can workaround this by setting

export LC_ALL=en_US

for your bash session. This can be placed in front of the compilation command as well. e.g.

LC_ALL=en_US gcc -o outfile srcfile.c

But the effect in that case will be only on the subsequent command.

Another case is that probably your source code may have been edited in windows maybe? Anyhow it might contain some weird characters for some reason.

You should check it in vim by enabling to show all characters

:set invlist

Hope this helps!

share|improve this answer
    
To clarify, it's not the source file that displays odd characters, it's the compiler error lines that appear in the terminal. The source file is fine. The problems above only appear if I have a compile error, like a syntax mistake. But that's just a red herring. The real issue is the terminal and the above is simply a consistent symptom. –  chrisaycock Mar 29 '11 at 23:24
    
you mean that if you just cat the source file the output is ok? –  g24l Mar 30 '11 at 0:44
    
@g24l Yes, the source file is fine. Only the error message from the compiler when displayed on the terminal is messed-up. I can compile my program by correcting a simple and unrelated syntax mistake. I was just curious as to why the terminal displays the characters incorrectly when output as part of a compiler error. –  chrisaycock Mar 30 '11 at 3:02
    
probably the compiler is running with a different locale. try inserting at the front of the command line something like LC_ALL=en_US or whatever you think appropriate. –  g24l Mar 31 '11 at 0:41
    
@g24l LC_ALL=en_US worked! Edit your answer so I can accept it! –  chrisaycock Mar 31 '11 at 1:58
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.