I am new to Visual Studio. I’m trying to run Hello World, but am getting several errors and cannot figure out what the problem is.
I typed:
#include<stdio.h>
main()
{
printf("Hello World");
}
into a code file with .c extension. I get this:
Error 1 error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
d:\Users\...\MSVCRTD.lib(crtexe.obj) Project
Error 2 error LNK1120: 1 unresolved externals
d:\users\...Project.exe 1 1 Project
Anyone know what the problem is?
Thanks.
It compiles fine… you need to set it to compile as C code:
Project->Properties->Advanced->Compile As C Code (/TC flag)
Output:
Reason:
You are compiling as C code and therefore default int is not assumed in C++ code
Update:
As mentioned by Michael Burr your code should use a
*.cextension. However, it will still compile cpp files as c code if you set the project properties. However, if no setting is provided it will compile with the default settings(*.c -> c code)and(*.cpp -> cpp code).Compiled as C code with CPP extension (successful)
Compiled as CPP code with C Extension (failed)