The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Undefined reference to WinMain@16 is a linker error: the final executable is missing the startup entry point required by its target type. A console program normally needs main or wmain; a Windows GUI program needs WinMain or wWinMain. First check that your entry point matches the selected subsystem, then confirm its source file is included in the link.
What WinMain@16 means
The diagnostic does not mean every program must define a function named WinMain@16. The selected subsystem determines which entry point the linker expects:
| Target type | Expected entry point | Typical use |
|---|---|---|
| Console | main or wmain | Command-line programs |
| Windows | WinMain or wWinMain | GUI programs that do not require a console |
See Microsoft’s /SUBSYSTEM documentation and its LNK1561 entry-point guidance for documented causes such as missing source files, incorrect names or signatures, and wrong project or linker settings.
Solution 1: Use main and select the console subsystem
For an ordinary console program, define a lowercase entry point such as int main(void) { return 0; } in C or int main() { return 0; } in C++. Names are case-sensitive: Main is not main. Check that the function is not hidden behind a preprocessor condition.
#1 Best Overall
Visual Studio
- Open Project → Properties.
- Select Configuration Properties → Linker → System.
- Set SubSystem to Console (/SUBSYSTEM:CONSOLE).
- Apply the setting to the configuration you are building, such as Debug or Release.
- Clean and rebuild the solution.
The corresponding linker option is /SUBSYSTEM:CONSOLE. Do not select the Windows subsystem just because the diagnostic mentions WinMain; that setting makes the linker look for a GUI entry point.
Solution 2: Define WinMain for a genuine GUI application
If the application is intended to start as a native Windows GUI program, provide the matching entry point. Microsoft documents WinMain with a narrow-character command-line parameter and wWinMain with a wide-character parameter. Select Windows (/SUBSYSTEM:WINDOWS) under Project → Properties → Configuration Properties → Linker → System → SubSystem, then clean and rebuild. The corresponding linker option is /SUBSYSTEM:WINDOWS.
Rank #2
Use this configuration for an application that does not require a console and typically creates its own windows. A GUI target with only main still has an entry-point mismatch.
Solution 3: Make sure the entry-point source file is linked
A source file can compile successfully without being included in the final executable. Check the build log: the final link command must include the object file generated from the file defining main, wmain, WinMain, or wWinMain.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWhat to check
- Confirm the entry-point file belongs to the executable target.
- Check whether it is excluded from the current build configuration.
- Confirm it is being compiled as C or C++, not treated as a header or arbitrary text file.
- Clean the project and inspect the complete linker command for the entry-point object.
- If you added a new source file, add it to the executable target, save the project, and rebuild.
A reported Code::Blocks workaround for source search problems is Settings → Compiler → Build options → Explicitly add currently compiling file’s directory to compiler search dirs. This is a version-specific reported option, not a guaranteed repair or universal current menu path.
Solution 4: Correct SDL or framework startup-library settings
Framework projects can require an additional startup library. A reported Code::Blocks SDL setup uses the link-library sequence mingw32;libSDL.a;libSDLmain.a and adds library folders under Project → Build Options… → Search directories → Linker. The reported library path is Project → Build Options… → Linker Settings → Link libraries → Add.
Rank #4
This SDL example does not apply to an unrelated console program. Use the libraries and startup objects required by your framework and compiler. GNU ld searches archives according to their position on the link command line, so follow the framework’s documented library order. See the reported Code::Blocks/SDL example and the GNU ld documentation.
Other causes to check
- Wrong spelling, capitalization, or signature: the entry point must match the expected name and parameters.
- Wrong subsystem: WINDOWS expects WinMain or wWinMain; CONSOLE expects main or wmain.
- Wrong target type: if you intend to build a DLL, configure it as a DLL rather than an executable.
- Custom /ENTRY setting: an incorrect custom entry point can override the normal selection; remove it unless deliberately needed.
- Unsaved or omitted project state: verify the actual source files and link command rather than assuming what the editor displays.
A quick decision process
- For a command-line program, define lowercase main and select CONSOLE.
- For a native GUI program, define WinMain or wWinMain and select WINDOWS.
- If the entry point exists, verify its source file and object file are included in the final link.
- For SDL or another framework, verify the startup library, library directories, subsystem, and library order.
- If the cause is still unclear, check the target type and any custom /ENTRY setting.
FAQ
Is WinMain@16 a function I should add to my source code?
Usually not. It is a linker symbol in the diagnostic. Use WinMain or wWinMain only for a GUI application; a console program should use main or wmain.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Best Value
Will enabling -mwindows always fix this error?
No. A Windows-subsystem option is appropriate for a GUI executable. It does not fix a console program whose main source file is missing from the link.
Why does the program compile but fail during linking?
Compilation checks source files individually. Linking combines object files and libraries and must find the entry point. A file containing main can compile but still be absent from the executable target.
Does Code::Blocks itself cause the error?
No. The underlying issue is usually an absent or mismatched entry point, an omitted source file, a wrong target type, or incorrect linker or framework settings.
The Bottom Line
For a console program, use main or wmain with the console subsystem. For a native GUI program, use WinMain or wWinMain with the Windows subsystem. If the entry point already exists, confirm its source file is linked; for SDL and similar frameworks, check startup libraries and their order. Adding WinMain blindly is not a general solution.
Recommended Free Tools
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

