简体   繁体   English

Visual C++ 没有编译我的代码

[英]visual C++ is not compiling my code

This code:这段代码:

#include <windows.h>
int WINAPI _WinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow);

Results in this output:此输出中的结果:

LNK1120: 1 unresolved externals

LNK2019: unresolved external symbol _WinMain@16 reference in function "int _cdecl invoke_main (void)" (? invoke_main@@Y AHZX)

Can someone please tell me what this means and how to fix it?有人可以告诉我这是什么意思以及如何解决吗?

LNK1120: 1 unresolved externals LNK1120:1 个未解析的外部

One or more symbols has gone unresolved while linking your program.链接您的程序时,一个或多个符号未解析。 More on that later.稍后再谈。

LNK2019: unresolved external symbol _WinMain@16 reference in function "int _cdecl invoke_main (void)" (? invoke_main@@Y AHZX) LNK2019: 函数“int _cdecl invoke_main (void)”中未解析的外部符号 _WinMain@16 引用(?invoke_main@@Y AHZX)

Names one of the missing symbols as _WinMain@16 .将缺失的符号之一命名为_WinMain@16 What the @16 on the end means is a rather long answer unto itself.最后的@16 本身意味着一个相当长的答案。 It would be best to look up "Name Mangling" and "Calling Convention" with the web search of your choice.最好通过您选择的网络搜索来查找“Name Mangling”和“Calling Convention”。

As for why _WinMain is missing,至于为什么缺少_WinMain

int WINAPI _WinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow);

only states that the programmer assures the compiler that somewhere else只声明程序员向编译器保证在其他地方

int WINAPI _WinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow)
{
    // does stuff
    return resultOfStuff;
}

exists.存在。

The compiler will be quite happy with this promise and move on, trusting that the programmer will make good at some later point in the file or in some other file.编译器会对这个承诺非常满意并继续前进,相信程序员会在文件或其他文件中的某个稍后点做好。

Once all of the code is compiled into object files, the linker comes along and attempts to put the pieces together into a program or library.一旦所有代码都编译成目标文件,链接器就会出现并尝试将这些片段组合到一个程序或库中。 It goes through all the object files matching up promised names with the address of the promised item.它遍历所有对象文件,将承诺的名称与承诺的项目的地址相匹配。

If the programmer is lying, then the linker will not find the promised function, will not have an address to use, and will return an error message saying the function is missing.如果程序员在撒谎,那么链接器将找不到承诺的函数,将没有可用的地址,并将返回一条错误消息,指出该函数丢失。

Solution: Implement the function.解决方法:实现功能。

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

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