Jagr
Jagr

Reputation: 502

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.

Upvotes: 0

Views: 122

Answers (1)

CS Pei
CS Pei

Reputation: 11047

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.

Upvotes: 1

Related Questions