[BUG]undefined reference to `WinMain' #13691
Unanswered
Thomas-mci-21
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Problem Description:

I'm working on a C++ project using CUDA and OptiX in VSCode with MinGW as the compiler. The goal is to create a console application. However, during the compilation process (I used make), I'm encountering the following linker error:
This error indicates that the linker is looking for an entry point named WinMain, but I have defined main as the entry point in main.cpp.



This is my Makefile (sorry for Chinese):
And these are all my codebase:
What I've Tried:
Confirmed the main function is used as the entry point:
In main.cpp, the entry point is correctly defined as int main(), not WinMain.
Used -mconsole in the Makefile:
I’ve set the -mconsole flag in the Makefile to ensure the program is compiled as a console application (not a GUI app).
CXXFLAGS = -std=c++17 -O2 -Wall -mconsole
Set the entry point to main with -Wl,--entry=main:
I explicitly set the entry point to main in the linker flags.
LDFLAGS = -L$(LIB_PATH) -L$(LIB_PATH_CUDA) -lcudart -lcuda -lcufft -Wl,--entry=main -mconsole
Checked linker error:
The error is still undefined reference to WinMain, meaning the linker is trying to find WinMain instead of main.
Tried removing -Wl,--entry=main:
I removed the -Wl,--entry=main flag, but the problem persists.
How can I solve this? Thanks for any help!
Beta Was this translation helpful? Give feedback.
All reactions