Undefined reference to WinMain@16 - Codeblocks

前端 未结 2 1977
礼貌的吻别
礼貌的吻别 2021-01-28 21:50

I have read: undefined reference to `WinMain@16' & still don\'t understand my problem.

I had a program that was working. Added a class but had not implemented it

2条回答
  •  北海茫月
    2021-01-28 22:14

    The problem is that your new project has been created as a Win32 GUI project, when it should have been created as a Console application. The former requires that a function with the signature int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) exists, while the latter requires one of the usual form taken for C or C++ projects, namely int main() or int main(char *argv[], int argc).

    Either create a new project of the console type and copy your code into it, or use the 'sticky-tape' solution, and change int main() to int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) You would also need to navigate to the project's properties and change the Build Target from GUI application to Console application - failing to do so would mean that you would not see any output, since you're using cout, which prints to stdout, which is shown by the console. This window is always available for a console application, but is only available for the Debug version of a GUI application.

    I reccomend doing it properly and creating a new project of the appropriate type, namely a Console application. :)

提交回复
热议问题