My problem in using VS 2015

Apr 26, 2016 at 8:45am
I just installed MS VS 2015 Enterprise (IDE) on my Windows 7 machine and created a new Win32 Project names "test1" and wrote the following code in it to test the IDE for getting started to write codes:

1
2
3
4
5
6
#include <iostream>
using namespace std;

int main() {
	return 0;
}


But (although that IDE is installed successfully, I get errors when running the code using F5. They are as follows:

Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol _WinMain@16 referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) test1 c:\Users\me\documents\visual studio 2015\Projects\test1\test1\MSVCRTD.lib(exe_winmain.obj) 1

Severity Code Description Project File Line Suppression State
Error LNK1120 1 unresolved externals test1 c:\users\me\documents\visual studio 2015\Projects\test1\Debug\test1.exe 1

Why do I get these errors please and how to get the code run?
Last edited on Apr 26, 2016 at 8:47am
Apr 26, 2016 at 9:53am
Firstly, those aren't run-time errors, they're link errors. I'd recommend understanding the difference between compiling, linking, and running your software, because that will help you understand better how to fix problems when they arise.

If I remember right, you'll need to create your project as an "Empty project". If you create it as one of the Windows application types, you'll need to tie your code into Windows framework stuff - including the main function, which is the source of this error.
Apr 26, 2016 at 10:46am
Yes, as they show, they are linking errors. And I also created the project as an empty one.
Apr 26, 2016 at 11:19am
You said:

and created a new Win32 Project

That's different from creating an Empty Project. Have you tried that? And, if so, is it now working?
Last edited on Apr 26, 2016 at 11:19am
Apr 26, 2016 at 11:32am
If you create a Win32 Project you will need a WinMain function as entry point.
Since you have only a main function you need to create a console project.

Apr 26, 2016 at 11:36am
1. On the menu bar, choose Project => Properties.
2. On the left pane of the dialog, select the Linker folder.
3. In the Linker folder, select the System property page.
4. On the right pane, change the SubSystem property to Console (/SUBSYSTEM:CONSOLE) (select from list)

Next time that you create a project, choose Win32 => Win32 Console Application and you wouldn't have to modify project settings later.
Apr 26, 2016 at 12:50pm
Thank you very much JLBorges. The problem is solved. :)
Also thanks to all for their replies.
Topic archived. No new replies allowed.