1

I recently installed Microsoft Visual Studio 2017. Whenever I try to compile my C code I get an error that says,

Unable to start program.
"c:\users\myname\source\repos\ConsoleApplication2\Debug\ConsoleApplication2.exe'.
The system cannot find the file specified.

I wrote my code by choosing, file > new project > Windows Console Application > source files (right-click) > add > new item > filename.c

For compiling I am using Local Windows Debugger and compiling as C code(/TC) from the advanced properties option.

How can I make my program work? My code is right because it compiles in another IDE perfectly.

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
Serene
  • 59
  • 2
  • 8
  • 1
    Possible duplicate of ["The system cannot find the file specified" when running C++ program](https://stackoverflow.com/questions/16511925/the-system-cannot-find-the-file-specified-when-running-c-program) – Jean-Baptiste Yunès Mar 08 '19 at 08:35
  • This is a very common problem, search "visual Unable to start program. The system cannot find the file specified.", you will get plenty of answers. – Jean-Baptiste Yunès Mar 08 '19 at 08:36
  • What's your vs2017 version, after 15.7.3, if we create the windows console application, first we need to remove the pch.h and all the .cpp file under source files. After that, change "Precompiled Header" to "Not using...". – LoLance Mar 08 '19 at 11:04
  • 1
    Make sure build the project successfully before using Local Windows Debugger. Also, what about create a new project, does this issue persists? You can try to create the project in another way following [this](https://www.youtube.com/watch?v=Slgwyta-JkA). – LoLance Mar 08 '19 at 11:06
  • @LanceLi-MSFT Thank you so much!! that video fixed everything!!! – Serene Mar 09 '19 at 17:55

2 Answers2

0

As Lance Li-MSFT mentioned in his comment I went and saw the video https://www.youtube.com/watch?v=Slgwyta-JkA

It basically said to do this:

New project > Windows Desktop > Windows Desktop Wizard > check Empty Project > uncheck Precompiled Header and SDL(if it's there) > Application type: Console Application > righ-click Source Files > Add > C++ File(.cpp) > fileName.c > write code > to compile click Local Windows Debugger

I know it looks like a lot but it's actually really simple and easy!

Serene
  • 59
  • 2
  • 8
  • 1
    Glad to know my comment helps. You can mark this answer so that other members with similar issue can benefit from it. – LoLance Mar 11 '19 at 01:37
  • @LanceLi-MSFT but why isn't your comment not on a bigger view? why is just a line under comment section?? I would choose your answer as the best one but I can only upvote. – Serene Mar 12 '19 at 17:41
  • Yes, you're right. Thanks for your feedback.Have a nice day! – LoLance Mar 13 '19 at 01:50
0

Actually,in VS2017(especially 15.7.3 or higher versions),we usually create new C projects by :

create C++ Windows Desktop=>Windows Desktop Wizard=>Empty Project This is the much easier way to create a simple C project in VS.

Also, we can create Windows Console Application(C++),this way we need to remove the pch.h and all the .cpp file under source files, (disable "Precompiled Header" if we only need to create a simple project), add a C class to make it work.

LoLance
  • 25,666
  • 1
  • 39
  • 73