I\'m learning C++ with Code::Blocks, and everytime i try to create a new class, I get an error message saying:
undefined reference to `WinMain@16\'
I just had the exact same problem working with the exact same tutorials.
How to solve this? I found that restarting CodeBlocks gets rid of this error. It has nothing to do with how you created the files or any of your syntax. A restart does the trick.
Why does this occur? If I had to take a wild guess, I would think that CodeBlocks does indeed create the header/cpp files, it does not however link them to your project in a proper way that makes them usable (although it does ask you to link them to the project after you create them). This is a guess.
I understand that some people have commented on this by saying that you're creating a Windows GUI console application instead of a console application, but this is not the case. I too was creating a simple console application as Bucky explains in the videos.
I just had this issue too! The problem was that I put my main function under a specific namespace while my classes were not part of this namespace and looked like I have no "main" for them. As soon as I removed the namespace/added the classes to the same namespace the build issue was gone.
its very simple and worked for me ... all you have to do is selecting " open an existing project " that appears in the start tab once you open code blocks and then you choose (your project name ).cbp file ... the program will open your projects as well as the class name .h and .cpp files ... you build and run ... and voila your code will work just fine ..
Go to "Project" --> "Build Options . . ."
on menu bar
Go to "Linker Settings"
tab
In "Link libraries"
panel, click "Add"
Write this in the coming up field: mingw32;libSDL.a;libSDLmain.a
Go to "Search directories" --> "Linker"
tab
Add your MinGW library folders there! Good Luck!!
This problem appeared to me because the "main.cpp" was not included in the project. If you see that error once again, just make sure you have all the files included in your project.
I've fixed this by opening the compiler settings dialog and simply clicking OK. Nothing changed. And it really works!
But if you add a new class again, this problem repeats. So, just open/close settings dialog every time you create a new class.