user5853385
user5853385

Reputation:

My Win32 C++ 'Hello World program' won't compile

So my go to language is C#, so I decided to learn C++. I made a hello world program with this code

#include <stdio.h>    // include the standard input/output header file

void main(void)    // our program starts here
{
printf("Hello World!");    // print "Hello World!" into the console
return;    // return void to windows
}

But I then get this error when I compile (I am using Visual Studio 2015)

Error   LNK1120 1 unresolved externals  Render Engine   c:\users\kamaldeep rai\documents\visual studio 2015\Projects\Render Engine\Debug\Render Engine.exe  

Error   LNK2019 unresolved external symbol _WinMain@16 referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) Render Engine   c:\Users\kamaldeep rai\documents\visual studio 2015\Projects\Render Engine\Render Engine\MSVCRTD.lib(exe_winmain.obj)

Upvotes: 3

Views: 3660

Answers (2)

Ajay
Ajay

Reputation: 18411

In addition to Paul's answer, here is how you can change the configuration so that linker would look for main:

  1. Open Project Properties
  2. Goto Linker
  3. System -> Subsystem
  4. Change it to Console

Also, your main prototype is not compliant with C++, it should return int

Upvotes: 6

PaulMcKenzie
PaulMcKenzie

Reputation: 35440

This error:

Error LNK2019 unresolved external symbol _WinMain@16

is caused by not choosing the correct project type when building your application. Since you're using Visual Studio, you want to have a Win32 Console Application project.

Instead, you chose a project that has WinMain as the entry point instead of the traditional main entry point.

Upvotes: 3

Related Questions