简体   繁体   中英

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

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)

Names one of the missing symbols as _WinMain@16 . What the @16 on the end means is a rather long answer unto itself. It would be best to look up "Name Mangling" and "Calling Convention" with the web search of your choice.

As for why _WinMain is missing,

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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