Can not run basic C++ program VS 2015

1

0

I have installed Visual Studio 2015 on my Windows 10 PC in order to create a C++ simple program.

Even if I try to run a basic Hello World program like this:

#include <iostream>

int main() {

    std::cout << "Hello world";

    return 0;
}

And click the Local Windows Debugger button to run the code VS2015 freezes and I have to kill it form task manager.

The worst part is that sometimes it leaves C++ program running and it can not be killed (not even with taskkill /f /pid and I have to reboot the PC so that I can try to build again without getting a program.exe is in use error.

So, VS installation is new and I also had to install the Win32 (C++) support which no longer installs by default.

Any suggestions on what might be wrong or how could this be fixed?

Thank you!

Cristy

Posted 2015-11-18T09:47:22.333

Reputation: 331

What did you install exactly? Your statement that you had to "install" Win32 support on your Windows 10 because it wasn't installed by default isn't correct. Windows has to support Win32 applications by default for a variety of reasons. – Ramhound – 2015-11-18T12:29:36.140

1So out of those 4 plus different packages what did you install precisely? Update your question to include this information. Use specific feature names. What toolset are you using precisely? – Ramhound – 2015-11-18T17:33:50.277

Common Tools for Visual C++ 2015. Also installed MFC after, but still the same result. Whenever I try to run a hello world program the whole IDE just freezes (it says Build started in the log, then I think it tries to run the executable and says Build successful in the status bar). – Cristy – 2015-11-18T18:27:46.327

1Suggestions: (1) Fully patch your installation of VS2015 via VS itself and Windows Update (attention to optional updates). (2) Disable your antivirus (if this helps then get another one). (3) Try to rename the folder %LocalAppData%\Microsoft\VisualStudio\12.0\ComponentModelCache and start VS. At startup, VS will rebuild the cache. – harrymc – 2015-11-21T09:38:52.613

@harrymc Tried that, it fixed other problem I had (with a C# project not starting) but C++ hello world still doesn't want to start, freezes VS after build. – Cristy – 2015-11-22T20:44:31.417

You mean that C# programs now work but not C++? Have you tried other C++ programs (i.e. is it a general C++ problem) ? Try starting devenv with /SafeMode parameter to see if this is an add-on problem.

– harrymc – 2015-11-22T21:29:55.610

C# always worked. It just happened today for a C# project (after I pulled some changes) to no longer work. Deleting the ComponentModelCache mentioned above helped fix this issue, but did not affect in any way the C++ problem. I tried creating other C++ project and it shows this: Severity Code Description Project File Line Error LNK2019 unresolved external symbol _WinMain@16 referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) – Cristy – 2015-11-22T21:37:02.033

1

This is a normal problem with your project, not with VS: You're compiling a Windows exe, not a console exe, so you're expected to either provide a WinMain function containing an event loop, or to convert the project to Console. See this thread for more info. If you confirm that the problem is solved, I will post this as an answer.

– harrymc – 2015-11-23T06:45:31.727

Answers

4

Since Visual Studio version 2012, the contents of the cache folder can unexpectedly get corrupted and/or out of sync and cause all sorts of unexpected behavior, including the one you reported.

There are no good explanations found as to the cause of the problem, or a link with one particular add-on, but the solution is quite simple: Delete the contents of the component model cache. Some people report that it is enough to delete the file Microsoft.VisualStudio.Default.cache inside this location.

The cache itself gets rebuilt automatically when Visual Studio restarts, and the process is rapid enough so that some people, encountering this problem too frequently, even call VS via scripts that delete this folder before starting VS.

For VS2015 the cache is in :
%AppData%\..\Local\Microsoft\VisualStudio\14.0\ComponentModelCache.

For VS2013 :
%AppData%\..\Local\Microsoft\VisualStudio\12.0\ComponentModelCache

For VS2012 :
%AppData%\..\Local\Microsoft\VisualStudio\11.0\ComponentModelCache

harrymc

Posted 2015-11-18T09:47:22.333

Reputation: 306 093

1It turned out to be the avast anti-virus... Thanks for your comments! – Cristy – 2015-12-01T20:26:23.893

I had the same problem and it root cause was also the anti-virus application – mspoerr – 2016-02-26T21:49:18.120

1

So as I see Cristy solved the problem and that is good. But, no offence intended, the answer was not very complete. I had the same problem:

  • VS community 2015 (newly installed)
  • C++ Program makes VS hangs at execution and process needs to be terminated
  • C++ Program process cannot be killed either in taskmanager or CMD

As Cristy pointed out, it was due to Avast. You can stop the Avast Antivirus service in services.msc and the process will either terminate on its own your you can do it manually.

To avoid the problem in the future you can go to Avast Parameters >> Active Protection >> Personalize >> untick the "Scan Programs at Execution" option.

This worked for me and I can now run my programs and they do not hang.

Hope that helps.

NevJ

Posted 2015-11-18T09:47:22.333

Reputation: 11

-1

I had this issue in VS 2012 windows 7. Root cause is Avast Antivirus. Fix is disable Avast whenever needed to work on C++ console applications (or) Go to Avast Settings > Active Protection > File System Shield (Customize) > uncheck Scan programs when executing

GreenHeart

Posted 2015-11-18T09:47:22.333

Reputation: 1