Issues with hello world wxWidgets project in Code::Blocks

135 Views Asked by At

While I was building the "hello world" project from the official wxWidget site in Code::Blocks, I got the following error:

||=== Build: Debug in wxTest2 (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function `ZN8wxObjectaSERKS_':|
C:\Program Files (x86)\wxWidgets\include\wx\object.h|394|undefined reference to `wxObject::Ref(wxObject const&)'|
obj\Debug\main.o||In function `ZN23wxCriticalSectionLockerC1ER17wxCriticalSection':|
C:\Program Files (x86)\wxWidgets\include\wx\thread.h|307|undefined reference to `wxCriticalSection::Enter()'|
obj\Debug\main.o||In function `ZN23wxCriticalSectionLockerD1Ev':|
C:\Program Files (x86)\wxWidgets\include\wx\thread.h|312|undefined reference to `wxCriticalSection::Leave()'|
obj\Debug\main.o||In function `ZN11wxTrackable10RemoveNodeEP13wxTrackerNode':|
C:\Program Files (x86)\wxWidgets\include\wx\tracker.h|57|undefined reference to `wxTheAssertHandler'|
C:\Program Files (x86)\wxWidgets\include\wx\tracker.h|57|undefined reference to `wxOnAssert(char const*, int, char const*, char const*, char const*)'|
C:\Program Files (x86)\wxWidgets\include\wx\tracker.h|57|undefined reference to `wxTrapInAssert'|
C:\Program Files (x86)\wxWidgets\include\wx\tracker.h|57|undefined reference to `wxTrapInAssert'|
obj\Debug\main.o||In function `ZNK12wxWindowBase18GetBestVirtualSizeEv':|
C:\Program Files (x86)\wxWidgets\include\wx\window.h|534|undefined reference to `wxWindowBase::GetBestSize() const'|
obj\Debug\main.o||In function `ZNK12wxWindowBase12CanBeFocusedEv':|
C:\Program Files (x86)\wxWidgets\include\wx\window.h|757|undefined reference to `wxWindowBase::IsEnabled() const'|
obj\Debug\main.o||In function `ZN12wxWindowBase25ProcessWindowEventLocallyER7wxEvent':|
C:\Program Files (x86)\wxWidgets\include\wx\window.h|892|undefined reference to `wxEvtHandler::ProcessEventLocally(wxEvent&)'|
obj\Debug\main.o||In function `ZNK12wxWindowBase10HasCaptureEv':|
C:\Program Files (x86)\wxWidgets\include\wx\window.h|1128|undefined reference to `wxWindowBase::GetCapture()'|
obj\Debug\main.o||In function `ZNK12wxWindowBase20GetDefaultAttributesEv':|
C:\Program Files (x86)\wxWidgets\include\wx\window.h|1209|undefined reference to `wxWindowBase::GetClassDefaultAttributes(wxWindowVariant)'|
obj\Debug\main.o||In function `ZNK12wxWindowBase19DoGetBestClientSizeEv':|
C:\Program Files (x86)\wxWidgets\include\wx\window.h|1935|undefined reference to `wxDefaultSize'|
C:\Program Files (x86)\wxWidgets\include\wx\window.h|1935|undefined reference to `wxDefaultSize'|
obj\Debug\main.o||In function `ZN8wxWindowC2Ev':|
C:\Program Files (x86)\wxWidgets\include\wx\msw\window.h|35|undefined reference to `wxWindowBase::wxWindowBase()'|
C:\Program Files (x86)\wxWidgets\include\wx\msw\window.h|35|undefined reference to `vtable for wxWindow'|
C:\Program Files (x86)\wxWidgets\include\wx\msw\window.h|35|undefined reference to `wxWindow::Init()'|
C:\Program Files (x86)\wxWidgets\include\wx\msw\window.h|35|undefined reference to `wxWindowBase::~wxWindowBase()'|
obj\Debug\main.o||In function `ZN8wxWindow14ShowWithEffectE12wxShowEffectj':|
C:\Program Files (x86)\wxWidgets\include\wx\msw\window.h|89|undefined reference to `wxWindow::MSWShowWithEffect(bool, wxShowEffect, unsigned int)'|
obj\Debug\main.o||In function `ZN8wxWindow14HideWithEffectE12wxShowEffectj':|
C:\Program Files (x86)\wxWidgets\include\wx\msw\window.h|94|undefined reference to `wxWindow::MSWShowWithEffect(bool, wxShowEffect, unsigned int)'|
obj\Debug\main.o||In function `ZN8wxWindow20MSWEndDeferWindowPosEv':|
C:\Program Files (x86)\wxWidgets\include\wx\msw\window.h|788|undefined reference to `wxDefaultPosition'|
C:\Program Files (x86)\wxWidgets\include\wx\msw\window.h|788|undefined reference to `wxDefaultPosition'|
C:\Program Files (x86)\wxWidgets\include\wx\msw\window.h|789|undefined reference to `wxDefaultSize'|
C:\Program Files (x86)\wxWidgets\include\wx\msw\window.h|789|undefined reference to `wxDefaultSize'|
obj\Debug\main.o||In function `ZN20wxTopLevelWindowBase8IsActiveEv':|
C:\Program Files (x86)\wxWidgets\include\wx\toplevel.h|214|undefined reference to `wxWindowBase::FindFocus()'|
C:\Program Files (x86)\wxWidgets\include\wx\toplevel.h|214|undefined reference to `wxWindowBase::IsDescendant(wxWindowBase*) const'|
obj\Debug\main.o||In function `ZN7wxFrame19MSWTranslateMessageEP6tagMSG':|
C:\Program Files (x86)\wxWidgets\include\wx\msw\frame.h|97|undefined reference to `wxFrame::MSWDoTranslateMessage(wxFrame*, tagMSG*)'|
obj\Debug\main.o||In function `ZN17wxMDIClientWindowC1Ev':|
C:\Program Files (x86)\wxWidgets\include\wx\msw\mdi.h|257|undefined reference to `vtable for wxMDIClientWindow'|
obj\Debug\main.o||In function `ZN20wxMDIParentFrameBase9TryBeforeER7wxEvent':|
C:\Program Files (x86)\wxWidgets\include\wx\mdi.h|401|undefined reference to `wxEVT_MENU'|
C:\Program Files (x86)\wxWidgets\include\wx\mdi.h|402|undefined reference to `wxEVT_UPDATE_UI'|
C:\Program Files (x86)\wxWidgets\include\wx\mdi.h|411|undefined reference to `wxWindowBase::IsDescendant(wxWindowBase*) const'|
C:\Program Files (x86)\wxWidgets\include\wx\mdi.h|419|undefined reference to `wxWindowBase::TryBefore(wxEvent&)'|
obj\Debug\main.o:main.cpp:(.rdata$_ZTV20wxMDIParentFrameBase[__ZTV20wxMDIParentFrameBase]+0x10)||undefined reference to `wxFrame::GetClassInfo() const'|
obj\Debug\main.o:main.cpp:(.rdata$_ZTV20wxMDIParentFrameBase[__ZTV20wxMDIParentFrameBase]+0x14)||undefined reference to `wxObject::CreateRefData() const'|
obj\Debug\main.o:main.cpp:(.rdata$_ZTV20wxMDIParentFrameBase[__ZTV20wxMDIParentFrameBase]+0x18)||undefined reference to `wxObject::CloneRefData(wxRefCounter const*) const'|
obj\Debug\main.o:main.cpp:(.rdata$_ZTV20wxMDIParentFrameBase[__ZTV20wxMDIParentFrameBase]+0x1c)||undefined reference to `wxWindowBase::SetNextHandler(wxEvtHandler*)'|
obj\Debug\main.o:main.cpp:(.rdata$_ZTV20wxMDIParentFrameBase[__ZTV20wxMDIParentFrameBase]+0x20)||undefined reference to `wxWindowBase::SetPreviousHandler(wxEvtHandler*)'|
obj\Debug\main.o:main.cpp:(.rdata$_ZTV20wxMDIParentFrameBase[__ZTV20wxMDIParentFrameBase]+0x24)||undefined reference to `wxEvtHandler::ProcessEvent(wxEvent&)'|
obj\Debug\main.o:main.cpp:(.rdata$_ZTV20wxMDIParentFrameBase[__ZTV20wxMDIParentFrameBase]+0x28)||undefined reference to `wxEvtHandler::QueueEvent(wxEvent*)'|
obj\Debug\main.o:main.cpp:(.rdata$_ZTV20wxMDIParentFrameBase[__ZTV20wxMDIParentFrameBase]+0x30)||undefined reference to `wxEvtHandler::SearchEventTable(wxEventTable&, wxEvent&)'|
obj\Debug\main.o:main.cpp:(.rdata$_ZTV20wxMDIParentFrameBase[__ZTV20wxMDIParentFrameBase]+0x38)||undefined reference to `wxWindowBase::TryAfter(wxEvent&)'|
obj\Debug\main.o:main.cpp:(.rdata$_ZTV20wxMDIParentFrameBase[__ZTV20wxMDIParentFrameBase]+0x40)||undefined reference to `wxFrame::GetEventTable() const'|
obj\Debug\main.o:main.cpp:(.rdata$_ZTV20wxMDIParentFrameBase[__ZTV20wxMDIParentFrameBase]+0x44)||undefined reference to `wxFrame::GetEventHashTable() const'|
obj\Debug\main.o:main.cpp:(.rdata$_ZTV20wxMDIParentFrameBase[__ZTV20wxMDIParentFrameBase]+0x48)||undefined reference to `wxEvtHandler::DoSetClientObject(wxClientData*)'|
obj\Debug\main.o:main.cpp:(.rdata$_ZTV20wxMDIParentFrameBase[__ZTV20wxMDIParentFrameBase]+0x4c)||undefined reference to `wxEvtHandler::DoGetClientObject() const'|
obj\Debug\main.o:main.cpp:(.rdata$_ZTV20wxMDIParentFrameBase[__ZTV20wxMDIParentFrameBase]+0x50)||undefined reference to `wxEvtHandler::DoSetClientData(void*)'|
obj\Debug\main.o:main.cpp:(.rdata$_ZTV20wxMDIParentFrameBase[__ZTV20wxMDIParentFrameBase]+0x54)||undefined reference to `wxEvtHandler::DoGetClientData() const'|
obj\Debug\main.o:main.cpp:(.rdata$_ZTV20wxMDIParentFrameBase[__ZTV20wxMDIParentFrameBase]+0x58)||undefined reference to `wxEvtHandler::WXReservedEvtHandler1(void*)'|
obj\Debug\main.o:main.cpp:(.rdata$_ZTV20wxMDIParentFrameBase[__ZTV20wxMDIParentFrameBase]+0x5c)||undefined reference to `wxEvtHandler::WXReservedEvtHandler2(void*)'|
obj\Debug\main.o:main.cpp:(.rdata$_ZTV20wxMDIParentFrameBase[__ZTV20wxMDIParentFrameBase]+0x60)||undefined reference to `wxTopLevelWindowMSW::Destroy()'|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build failed: 50 error(s), 0 warning(s) (0 minute(s), 4 second(s)) ===|

I am using Code:Blocks 20.3, Windows 10 x64, without the MinGW installation from Code::Blocks. I independently installed MYSYS2 MinGW compiler with gcc 13.2.0. And I am using wxWidgets 3.2.

I used CMake to build wxWidgets.
(I followed this tutorial to build it. Other tutorials that suggested to use mingw32-make -f makefile.gcc didn't work for me, and my command prompt throws error like: if not exist ".." mkdir "..". process. CreateProcess(null,..,..)failed.)

My Build options in Code::Blocks read:

"project name">search directories>compiler>C:\Programe Files(x86)\wxWidgets\include

"project name">search directories>linker>C:\Programe Files(x86)\wxWidgets\gcc_x64_dll
(i don't have "gcc_dll" folder in wxWidgets directory, only "gcc_x64_dll" is present)

Debug>Search directories>Compiler>C:\Programe Files(x86)\wxWidgets\gcc_x64_dll\mswud

Debug>Linker settings>Link libraries: "wxmsw32ud_core","wxbasw32ud"
(same for release, but without "d")

A few things that I tried out and didn't work:

  1. As some forums suggested that it's linker error and it had to do with linker settings. I tried various combination of libraries (of course remembering to change the version from 31 to 32 and keeping in mind to note the "ud" and "u" versions.). here are two of the combinations that I tried (for debugging): (libwxmsw32ud_core ; libwxbase32ud) (wxmsw32ud_core; wxbase32ud)

  2. I also tried building the project with only #include <wx/wx.h>in the main.cpp. It threw same undefined reference to type of error but this time when clicking on the error it opened some header files.

  3. I tried building the hello world program on a new project with nothing in the project build option to hopefully weed out something more. When I don't add the include directory to the compiler in search directories, it threw a single fatal error saying that it couldn't find the "wx.h" file. But when I add the include directory of wxwidgets, the fatal error now becomes undefined reference to.. type of error.

  4. Prior to all this, I tried to use prebuilt binary of wxWidgets. I got the same linker error on the pre built method. I also tried building it through command prompt with mingw32 -make -f makefile.gcc...... command. But I could never build it this way because the it gave error while building saying something like: (if not exist ".." mkdir "..". process: CreateProcess(Null, "...", ..). failed).

Please let me know if it's strictly just linking issue, or issue in building the library, or my Code::Blocks is setup wrong. (I am new to building projects and libraries. please be a little understanding if this is a very silly issue.)

2

There are 2 best solutions below

1
万顷茫然 On BEST ANSWER

At the end of Makefile.gcc, there should be some code like cmd=$(ComSpec). To avoid the CreateProcess failure, change it to cmd=C:\Windows\System32\cmd.exe. That is, replace $(ComSpec) with the value in the ComSpec environment variable. This change should be made to every makefile that MinGW32-make executes.

12
Xaviou On

It really seems to be a linker problem. Could you post the full command line used by Code::Blocks (to activate this, do to "Settings", "Compiler", select your compiler, go to the "Other settings" sub tab, and select "Full command line" as compiler logging option).

For you man build with mingw-make problem, you first have to run the command line with the "setup_h" build target :

mingw32-make -f makefile.gcc setup_h other_options_of_your_command_line

And when its done, you can launch the samea command line without the "setup_h" build target.

And if you don't want to loose your time with building the libs yourself (I know it takes a long time), you'll find my pre-build binaries here.