3

I am trying to build a project written in VS 2008 using QtCreator under Linux and I get loads of errors:

/home/ga/dev/CppGroup/MonteCarlo/main.cpp:1: error: stray ‘\377’ in program
/home/ga/dev/CppGroup/MonteCarlo/main.cpp:1: error: stray ‘\376’ in program
/home/ga/dev/CppGroup/MonteCarlo/main.cpp:1: error: stray ‘#’ in program
/home/ga/dev/CppGroup/MonteCarlo/main.cpp:1: warning: null character(s) ignored

etc.

Does it mean that the compiler can't handle unicode correctly? How can I fix it?

Grzenio
  • 35,875
  • 47
  • 158
  • 240

4 Answers4

6

That looks like a UTF-16 BOM for little-endian UTF-16. You need to make sure the file is saved as UTF-8 or convert it manually via iconv -f UTF-16LE -t UTF8 myfile.

DarkDust
  • 90,870
  • 19
  • 190
  • 224
  • But I want to make it compile on both systems at the same time... Can I configure VS to save it as utf-8? – Grzenio Mar 24 '11 at 11:17
  • @Grzenio: See [this question](http://stackoverflow.com/questions/696627/how-to-set-standard-encoding-in-visual-studio) or [this question](http://stackoverflow.com/questions/1838899/force-visual-studio-2010-to-save-all-files-in-utf-8) on how to set it, and [this question](http://stackoverflow.com/questions/279673/save-all-files-in-visual-studio-project-as-utf-8) on how to bulk-change all project files. – DarkDust Mar 24 '11 at 11:20
  • Is it possible to configure on the project or solution level? – Grzenio Mar 24 '11 at 11:58
1

Ensure the file is encoded in UTF-8. Open it with a text editor that allows you chosing the file encoding (e.g. gedit or notepad++) and convert it. I've had similar issues before, but UTF-8 files work fine (other encodings like UTF-16 won't work).

Edit: Don't convert your resource script (if there's any) to UTF-8. The resource compiler won't be able to read it (at least when using MSVC 2008).

Mario
  • 35,726
  • 5
  • 62
  • 78
  • But I want to make it compile on both systems at the same time... Can I configure VS to save it as utf-8? – Grzenio Mar 24 '11 at 11:15
  • MSVC will keep UTF-8 if the files are UTF-8 already and it will be able to use them as well. – Mario Mar 24 '11 at 11:16
0

It may be that your files use windows encoding, with characters like ^M, \r\n... Have you tried to run dos2unix on your source files before compiling ?

0x26res
  • 11,925
  • 11
  • 54
  • 108
0

I think i've seen 'stray ...' in file with unicode.

You may configure your editor's or console's (or both) encoding setting to fix it.

eugene
  • 39,839
  • 68
  • 255
  • 489