Weird characters in g++ compile errors â

If the locale of your environment isn’t compatible with the terminal you are using, g++ will spit out weird characters.  To check your current locale in Linux, use the command “locale” from the command prompt.  en_US.UTF-8 encoding was giving me the weird characters in a 32-bit CentOS distro running on a vmware machine.

Solution:

Enter the commands:  “export LC_ALL=C”   and  “export LANG=C”

After changing the locales, the characters in my g++ error messages disappeared but only for my current terminal session.  To change it permanently, I had to change the default locale setting.

Change the default locale in CentOS:

edit the file: /etc/sysconfig/i18n

edit the first line to be: LANG=”C”

All other terminal sessions should use the POSIX/C locale as the default now.