5

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.

  • Have you tried running the application under a debugger on Windows XP to find out where the access violation is happening? If you do not have Visual Studio installed on Windows XP you can set up [Remote Debugging](http://msdn.microsoft.com/en-us/library/vstudio/y7f5zaaa.aspx). Visual Studio ships with the source code for its CRT implementation. Make sure you add the directory to the *VC++ Directories*. – IInspectable Sep 10 '13 at 21:44
  • @IInspectable: Thanks for the idea of remote debugging. I will try that, but remote debugging with VS2012 and XP seems to be not easy: [Can I use the Visual Studio 2010 remote debugger on Windows XP to debug a .Net 4.0 app from Visual Studio 2012?](http://stackoverflow.com/questions/14444055/can-i-use-the-visual-studio-2010-remote-debugger-on-windows-xp-to-debug-a-net-4) – user2766445 Sep 11 '13 at 19:08
  • @IInspectable: Remote debugging does not work with Visual Studio 2012 and Windows XP. The Visual Studio 2012 remote debugger requires "a newer version of Windows". I tried to install Visual Studio 2010 remote debugger and tried to connect from Visual Studio 2012 - which did not work. – user2766445 Sep 12 '13 at 22:30
  • That's basically what I got from a link of the question you linked to. It seems you need Visual Studio 2010 to connect to a Windows XP machine. While you can install VS 2010 and VS 2012 side-by-side on the same machine this is certainly less than ideal, even though you can debug an application built on VS 2012 using VS 2010. It seems Microsoft have completely underestimated how many XP installations are still in use. – IInspectable Sep 12 '13 at 22:37

1 Answers1

2

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.