Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception in statically linked msvcrt using Visual Studio 2012

There seems to be a problem in the statically linked version of VS2012. Starting a console application on an old system leads to an exception, whenever streams are used, although new systems causes no trouble at all. To reproduce this error it is sufficient to

  • create a new console application in VS2012
  • add the line std::ofstream f; or std::cout << "Hello World"; in the main function (include fstream or iostream as required)
  • switch to v110_xp toolset (if required for Windows XP)
  • switch to statically linked libraries (/MT)
  • start the exe on an old system There is always an exception.

Removing the line with ofstream or cout always resolves the problem. Switching to dynamically linked runtime libraries (/MD) always resolves the problem. In case of ofstream, using size optimization (/O1) or no optimization (/Od) instead of speed optimization (/O2) resolved the problem.

Does anyone has an idea or hint? Thanks in advance.

like image 714
user2766445 Avatar asked Nov 01 '22 15:11

user2766445


1 Answers

Solved by myself - my first assumption was wrong:

Visual Studio 2012 uses SSE2 instructions by default. This causes trouble on old systems such as Intel Pentium III or AMD Athlon XP, which do not support SSE2. An invalid instruction exception is thrown. You can switch of SSE2 using the /arch:IA32 compiler option.

The dynamically linked msvcrt (DLL) does work in all case, as it is not affected by the /arch compiler option.

like image 199
user2766445 Avatar answered Nov 15 '22 06:11

user2766445