Let's say I am writing a C++ program and I want to add a new class.
I would have to go to File->New->Class... and then I select the class. I select "Create" and then the files appear. Everything was working before but now when I build and run I get
c:\mingw\bin\..\lib\gcc\mingw32\4.8.1\..\..\..\libmingw32.a(main.o):main.c:(.text.startup+0xa7)||undefined reference to `WinMain@16'|
Here is the build log:
-------------- Build: Debug in Hybrid (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -Wall -fexceptions -g -O3 -O2 -O1 -Wshadow -Winit-self -Wredundant-decls -Wfloat-equal -Wunreachable-code -Wmain -pedantic-errors -pedantic -std=c++11 -Wfatal-errors -Wall -I -c "C:\Documents and Settings\David Godfrey\Desktop\Projects\Hybrid\Foo.cpp" -o obj\Debug\Foo.o
The only class I added was Foo. Does anyone know why this is happening?
Yes, there is a bug that adds an empty include path in the settings.
You probably have to remove the empty path from the build options.
How exactly would I do that?
Also I notice in the build log that it's not linking with my main.cpp. How would I add it?
Can you post a screenshot with the class wizard dialog, just before you press the Ok button?
(http://i.gyazo.com/0257cd1351a61f4b0f2592bd94f2fbbe.png)
So you're trying to create a class without a name?
Here's one with the name:
(http://i.gyazo.com/568839e59161f2443fbcc80ee1b9e9b1.png)
Can't reproduce this problem on Linux.
Can someone with a windows try it?
I suppose you're clicking OK twice in the two dialogs that are shown after this one?
Quote from: SuperBoi45 on November 10, 2014, 08:30:09 PM
How exactly would I do that?
Also I notice in the build log that it's not linking with my main.cpp. How would I add it?
Is the file main.cpp part of your project?
If not, add it.
If yes, try rebuilding the project and post the full rebuild log.
I could NOT duplicate the problem on my own Windows build of Git SVN 10030 (I do NOT think any of my patches would affect this issue).
Edit: Please include the Code::Blocks version information.
Build log for console c++ created project then added class Foo
-------------- Build: ReleaseWin32 in testwinmainclass (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -Winit-self -Wmain -pedantic-errors -Wfatal-errors -Wall -fexceptions -O2 -Wmissing-include-dirs -Wno-unused-local-typedefs -Iinclude -c E:\Test\testwinmainclass\main.cpp -o obj\ReleaseWin32\main.o
mingw32-g++.exe -Winit-self -Wmain -pedantic-errors -Wfatal-errors -Wall -fexceptions -O2 -Wmissing-include-dirs -Wno-unused-local-typedefs -Iinclude -c E:\Test\testwinmainclass\src\Foo.cpp -o obj\ReleaseWin32\src\Foo.o
mingw32-g++.exe -o bin\ReleaseWin32\testwinmainclass.exe obj\ReleaseWin32\main.o obj\ReleaseWin32\src\Foo.o -s
Output file is bin\ReleaseWin32\testwinmainclass.exe with size 467.00 KB
Build log for Win GUI c++ created project then added class Foo2
mingw32-g++.exe -Wmain -pedantic-errors -pedantic -Wfatal-errors -Wall -std=c++11 -O2 -Wmissing-include-dirs -Wno-unused-local-typedefs -Iinclude -c E:\Test\guiframeaddnewclass\main.cpp -o obj\ReleaseWin32\main.o
mingw32-g++.exe -Wmain -pedantic-errors -pedantic -Wfatal-errors -Wall -std=c++11 -O2 -Wmissing-include-dirs -Wno-unused-local-typedefs -Iinclude -c E:\Test\guiframeaddnewclass\src\Foo2.cpp -o obj\ReleaseWin32\src\Foo2.o
mingw32-g++.exe -o bin\ReleaseWin32\guiframeaddnewclass.exe obj\ReleaseWin32\main.o obj\ReleaseWin32\src\Foo2.o -s -lgdi32 -luser32 -lkernel32 -lcomctl32 -mwindows
Output file is bin\ReleaseWin32\guiframeaddnewclass.exe with size 11.00 KB
Tim S.
I suggest trying only one optimization code at a time. Note, it is likely unrelated to your problem; but, it is a bad idea to set all three of them in most cases only one of them works.
-O3 -O2 -O1
Tim S.
stahta01: have you enabled all the options as show on the screenshot?
Quote from: oBFusCATed on November 11, 2014, 01:38:13 AM
stahta01: have you enabled all the options as show on the screenshot?
Prior to this no, but, I just checked the two that were missing and I still do NOT get the error.
The error would happen if main.cpp was NOT part of the windows project; this is the likely cause of the problem in my opinion.
Tim S.
Quote from: stahta01 on November 11, 2014, 02:16:06 AM
The error would happen if main.cpp was NOT part of the windows project; this is the likely cause of the problem in my opinion.
No you're wrong here (I think). The error happens because CB passes -I without a path and messes the command line.
@SuperBoi45: Can you do a full rebuild and then post the full build log?
I ran into the same problem a while ago, but I figured out a simple solution to it in case anyone is still having trouble. After creating a new class (with .h and .cpp files) and linking it to the project, you have to save the project, close it, and reopen it. Problem solved. I'm not sure why this works, but it does.
JonnyCrow: Can you post exact steps that reproduce the problem with a new minimal project?
Sorry for the late reply. Here's what you asked for:
1. I created a new project (just a console project).
(https://dl.dropboxusercontent.com/u/98744960/screenshot1.png)
2. Without changing any of the default code, I created a new class.
(https://dl.dropboxusercontent.com/u/98744960/screenshot2.png)
3. I added it to the current project.
(https://dl.dropboxusercontent.com/u/98744960/screenshot3.png)
4. I added the #include directive in main.cpp, and upon attempting to build the project, the 'undefined reference to WinMain@16' error appears.
(https://dl.dropboxusercontent.com/u/98744960/screenshot4.png)
5. I saved the project, closed it, and reopened it again.
(https://dl.dropboxusercontent.com/u/98744960/screenshot5.png)
6. When rebuilding the project, it works fine.
(https://dl.dropboxusercontent.com/u/98744960/screenshot7.png)
Not sure why this works, but closing the project and reopening it (or restarting Code::Blocks) solves the problem consistently.
Can someone else try these steps on windows and then tell me if the problem can be reproduced?
JohnnyCrow: Can you try to reproduce the bug using the latest nightly build?
Can you show the list of plugins you have enabled?
i can't reproduce this bug with a nightly (probably -10~20 commits) on win7
BlueHazzard: Can you try with the 13.12 release?
Yop, here it is:
-------------- Build: Debug in tmp4 (compiler: GNU GCC Compiler)---------------
[ 33.3%] mingw32-g++.exe -Wall -fexceptions -g -Wno-unused-local-typedefs -I -c G:\tmp\tmp4\main.cpp -o obj\Debug\main.o
[ 66.7%] mingw32-g++.exe -Wall -fexceptions -g -Wno-unused-local-typedefs -I -c G:\\tmp\tmp4\test.cpp -o obj\Debug\test.o
[100.0%] mingw32-g++.exe -o bin\Debug\tmp4.exe obj\Debug\main.o obj\Debug\test.o
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libmingw32.a(main.o):main.c:(.text.startup+0xa7): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
Process terminated with status 0 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))
Build log saved as:
And yes it is the -I option.... don't know why it is there... and why saving helps, but someone has fixed it in trunk...
[Edit:] saving project is not enough , you have to re open it, so the parser checks for plausibility...
Hm, thanks good to know it is fixed:)