Jagr Jagr - 3 years ago 284
C Question

Error in VS 2017 for C language

I am trying to set up a project in visual studios for C but every time i do, i first get this error message

fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?

then when i fix it by going into the "Properties->Precompiled header" i get this message

error LNK2005: _main already defined in clang.obj

. This has been going on for days now and i watched a bunch of videos and read a bunch of articles on this and I can't seem to find a fix. I just want to run my C program and have it execute without dealing with errors like those above. Here is what i do to set it up,

  1. Create new project -> Select "Windows console application" -> change the "Location" to a file directory on my desktop -> then go to "Project" and "Add new item" -> i name that item "name.c" and when I am done, I insert my code and run it then i receive the same errors. Can someone please help me.

Answer Source

I think the problem is that when you choose Windows console application template, VS 2017 already generated a file which has a int main() function defined in it.

Then you added another file name.c which also has a main() function. Thus you got that error.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download