Undefined Reference to Winmain (C++ Mingw)

Undefined reference to WinMain (C++ MinGW)

This example code uses wWinMain but

One thing to note is that Visual C++ supports a “wWinMain” entry point
where the “lpCmdLine” parameter is a “LPWSTR”. You would typically use
the “_tWinMain” preprocessor definition for your entry point and
declare “LPTSTR lpCmdLine” so that you can easily support both ANSI
and Unicode builds. However, the MinGW CRT startup library does not
support wWinMain, so you’ll have to stick with the standard “WinMain”
and use “GetCommandLine()” if you need to access command line
arguments.

via Building Win32 GUI Applications with MinGW

In this specific case, you can use WinMain instead. This program doesn't use pCmdLine value, so it should compile when you change wWinMain to WinMain and PWSTR pCmdLine to PSTR pCmdLine.

If you later would need unicode command line use LPWSTR cmd_line = GetCommandLineW(); instead of WinMain argument.

Newer Mingw versions also support -municode linker option switching to alternate startup code allowing to use wWinMain instead of WinMain (or wmain instead of main). Add it to your command line, linker options in IDE or makefile.

g++ other_options_and_arguments -municode

C Programming undefined reference to `WinMain@16'

I found What was wrong accidentally.After writing my code through notepad,I forgot to save file ctrl+s so i just trying to compile empty file.

Can't install SDL on MinGW, getting `undefined reference to WinMain@16`

SDL2-devel-2.0.0-mingw.tar.gz contains both 32-bit libraries (i686-w64-mingw32 directory) and 64-bit libraries (x86_64-w64-mingw32 directory).

The error was caused by using a 64-bit version of the library with a 32-bit compiler.

Make Failed on Undefined Reference to WinMain

Given that in a comment, you claim:

the main function is in main.c

and the output of the link operation (formatted for clarity) is

gcc -o build 
obj/teos_init.o
obj/teos_event.o
obj/teos_task.o
obj/teos_sem.o
obj/teos_linkedlist.o
obj/teos_log.o
-Iinc/pvt -Iinc/pub -fmax-errors=3 -std=c11

it's clear that your Makefile is not linking main.o so you don't have a main function.

The reason for this is that main.c is not listed in your list of source files from which the list of object files to link is built..

_SRC = teos_init.c teos_event.c teos_task.c teos_sem.c teos_linkedlist.c teos_log.c 
# No main.c here

Add main.c to the end of that line and see if that fixes anything.

GCC C++ linking error : Undefined reference to 'WinMain@16'

Rename your main to be WinMain with the following parameters

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR lpCmdLine, INT nCmdShow)
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Quit();

return 0;
}

Most of those parameters will require #include <windows.h> If that header is not available, then declare as:

int __stdcall WinMain(void*, void*, char*, int)


Related Topics



Leave a reply



Submit