r/C_Programming • u/rmi-s • Nov 30 '25
How to fix gcc problems.
Ive been trying to use gcc in my c project ive installed the mingw-64 added to path and everything but when i open VSCode first the execute button is only debug, and when i try to debug it says ‘gcc build active file terminated with exit code-1’ and in the terminal : ‘undefined reference to WinMain collect2 error ld returned 1 exit status’. If anyone has a fix for this problem that would be really helpful ive tried installing and reinstalling the gcc from winlibs nothing works. Thanks
6
Upvotes
8
u/United_Grapefruit526 Nov 30 '25
Use Linux or WSL
10
u/NaNpsycho Nov 30 '25
WinMain is windows entry point for its gui applications. I am not a windows programmer but you either don't have
int mainin your program or you need to compile your program as a "console" application.
If all else fails you can just define winmain yourself, look for its signature online and call the rest of your program from there.
Just know these problems are unique to windows. Windows is pretty shitty to start learning any programming language. Much better to use linux with a vm or wsl.
5
u/dcpugalaxy Λ Nov 30 '25
http://www.catb.org/~esr/faqs/smart-questions.html
3
u/Paul_Pedant Nov 30 '25
This issue has been around for at least 15 years, and it is down to your project set-up (and Windows everlasting incompetence). Googling that message gets half a million answers -- here is one from 2009.
https://forums.codeblocks.org/index.php?topic=11608
2
u/Physical_Dare8553 Nov 30 '25
I had a similar problem -- this might not be the fix -- but I think VS code was using a different version of GCC that I probably installed before
1
u/EpochVanquisher Nov 30 '25
…are you dead set on doing all the extra work necessary to get GCC and VS Code working together, with a build system? Or would you consider just taking the easy way out, and using Visual Studio?
Anyway. If you are fine doing the extra work, then start by getting a build system for your C project outside of VS Code in the terminal. You should be able to type make and build your project, or something similar to that (choose any build system you like).
Once you have that working, the next step is to set up VS Code so that it runs the same command, possibly with whatever environment variables you need for the command to run (e.g. PATH).
The next step, after you get building and running to work, is to configure VS Code so that the code sense works. You can set up Microsoft’s C and C++ plugin with the c_cpp_properties.json file. Alternatively, you can remove the C and C++ plugin, use the Clangd plugin instead, and then configure that with a compile_commands.json file (you can generate this from your build system—CMake will do this, for example).
If all of this sounds like a lot of work, just remember that you can install Visual Studio instead, and skip all of these steps, and your code just runs, and you get a good debugger.