简体   繁体   English

我的Win32 C ++'Hello World程序'将无法编译

[英]My Win32 C++ 'Hello World program' won't compile

So my go to language is C#, so I decided to learn C++. 所以我的语言是C#,所以我决定学习C ++。 I made a hello world program with this code 我用这段代码制作了一个hello world程序

#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) 但是我在编译时遇到这个错误(我正在使用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)

In addition to Paul's answer, here is how you can change the configuration so that linker would look for main : 除了Paul的回答,以下是如何更改配置以便链接器查找main

  1. Open Project Properties 打开项目属性
  2. Goto Linker Goto Linker
  3. System -> Subsystem 系统 - >子系统
  4. Change it to Console 将其更改为控制台

Also, your main prototype is not compliant with C++, it should return int 此外,您的main原型不符合C ++,它应该返回int

This error: 这个错误:

Error LNK2019 unresolved external symbol _WinMain@16 错误LNK2019未解析的外部符号_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. 由于您使用的是Visual Studio,因此您希望拥有一个Win32 Console Application项目。

Instead, you chose a project that has WinMain as the entry point instead of the traditional main entry point. 相反,您选择了一个以WinMain作为入口点而不是传统main入口点的项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM