Saturday, April 16, 2011

Adventures with Visual Studio 2010

How to prevent console from exiting immediatly when you run using Ctrl + F5:
With the new visual studio 2010 you might see this behavior even when you use ctrl f5 aka "start without debugging". This is most likely because you created an "empty project" instead of a "Win32 console application". If you create the project as a "Win32 console application" you can disregard this as it does not apply.

In the older versions it would default to the console subsystem even if you selected "empty project", but not in 2010, so you have to set it manually. To do this select the project in the solution explorer on the right or left (probably is already selected so you don't have to worry about this). Then select "project" from the menu bar drop down menus, then select "*project_name* properties" > "configuration properties" > "linker" > "system" and set the first property, the drop down "subsystem" property to "console (/SUBSYSTEM:CONSOLE)". The console window should now stay open after execution as usual.
When you have a C++ project with C files in it, you will get "error D8045: cannot compile C file". You need to change a setting [MSDN]:

1. Open the project's Property Pages dialog box.
2. Click the C/C++ folder.
3. Click the Advanced property page.
3. Modify the Compile As property and set it to /Tp. The /Tp option specifies that filename is a C++ source file, even if it doesn't have a .cpp or .cxx extension. Which is the case for C files which usually have .c extension.

No comments: