I got many compiler warnings for the eigen library, one example being:
Warning C4819 The file contains a character that cannot be represented in the current code page (950). Save the file in Unicode format to prevent data loss
Some suggestions were to re-save the files in Unicode, but doesn't that mean I "changed" the library source code and will reappear again after my next update of the library?
The error message is misleading because Eigen's source code is already encoded in UTF-8. The issue is that Visual Studio relies on the BOM to detect UTF. Using the BOM for that purpose is not officially recommended and including the BOM in a UTF-8 encoded file is not common practice in Linux, which is what Eigen3 primarily targets (we can argue the wisdom of that but this is neither here nor there). Failing to find a BOM, Visual Studio falls back to the current user code page.
This is compounded by Eigen3 being both a math library that likes to use math symbols in its comments and being written by many programmers from France with accents in their names. Its source code therefore uses symbols outside the ASCII subset. This causes the fallback to fail for some files.
Workaround: Tell the Visual Studio compiler to treat all source code files as UTF-8 with the compile flag /source-charset:utf-8
. Optionally simply set /utf-8
instead to also define the execution character set.
/source-charset:utf-8
Further details on the compiler flags in the official documentation:
It's only a workaround because you can only set one character set. When you pull in several projects with several conflicting encodings, this will fail. In that case, I'm not aware of any solution other than loading the files and saving them with a BOM or compatible encoding.