When building a C application, you may encounter the following error:
Error LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ)
This error typically arises when the following conditions are not met:
To resolve this issue, follow these steps:
Verify that your project includes a function called main() in the source code. This function serves as the entry point for the program and must be defined as follows:
int main(int argc, char** argv) { // Your program logic goes here return 0; }
Check your project's linker settings to ensure that the main() function is accessible from the main module. In Visual Studio, go to:
Confirm that the library containing the definition of main() is included in the project's linker settings. This can be found in:
#include "windows.h" int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) { MessageBox(NULL, _T("Hello, world!"), _T("My Application"), MB_OK); return 0; }
Note: In this example, main() is declared using the WINAPI macro because the WinMain() function is the entry point for Windows applications.
The above is the detailed content of Why am I getting the 'Error LNK2019 unresolved external symbol _main' in my C application?. For more information, please follow other related articles on the PHP Chinese website!