Code::Blocks 中的 hello world wxWidgets 项目存在问题

问题描述 投票:0回答:2

当我在 Code::Blocks 中从官方 wxWidget 站点构建“hello world”项目时,出现以下错误:

||=== 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)) ===|

我使用的是 Code:Blocks 20.3、Windows 10 x64,没有从 Code::Blocks 安装 MinGW。 我用gcc 13.2.0独立安装了MYSYS2 MinGW编译器。 我正在使用 wxWidgets 3.2。

我使用 CMake 来构建 wxWidgets。
(我按照 this 教程来构建它。建议使用

mingw32-make -f makefile.gcc
的其他教程对我来说不起作用,并且我的命令提示符会抛出错误,例如:
if not exist ".." mkdir "..". process. CreateProcess(null,..,..)failed.

Code::Blocks 中的我的构建选项为:

"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")

我尝试过但没有成功的一些事情:

  1. 正如一些论坛建议的那样,这是链接器错误,并且与链接器设置有关。我尝试了各种库组合(当然记得将版本从 31 更改为 32,并记住记下“ud”和“u”版本。)。 这是我尝试过的两种组合(用于调试): (libwxmsw32ud_core ;libwxbase32ud) (wxmsw32ud_core;wxbase32ud)

  2. 我还尝试在 main.cpp 中仅使用

    #include <wx/wx.h>
    来构建项目。它抛出了相同的
    undefined reference to
    类型的错误,但这次单击错误时它打开了一些头文件。

  3. 我尝试在一个新项目上构建

    hello world
    程序,项目构建选项中没有任何内容,希望能够清除更多内容。当我没有将
    include
    目录添加到搜索目录中的编译器时,它会抛出一个致命错误,指出找不到“wx.h”文件。 但是当我添加wxwidgets的
    include
    目录时,致命错误现在变成了
    undefined reference to..
    类型的错误。

  4. 在此之前,我尝试使用 wxWidgets 的预构建二进制文件。我在预构建方法上遇到了相同的链接器错误。我还尝试通过命令提示符使用

    mingw32 -make -f makefile.gcc......
    命令构建它。但我永远无法以这种方式构建它,因为它在构建时给出了错误,如下所示:
    (if not exist ".." mkdir "..". process: CreateProcess(Null, "...", ..). failed)

请告诉我这是否只是链接问题,或者构建库的问题,或者我的 Code::Blocks 设置错误。 (我是构建项目和库的新手。如果这是一个非常愚蠢的问题,请理解。)

c++ codeblocks wxwidgets
2个回答
0
投票

这确实是一个链接器问题。 您能否发布 Code::Blocks 使用的完整命令行(要激活此功能,请执行“设置”、“编译器”,选择您的编译器,转到“其他设置”子选项卡,然后选择“完整命令行”作为编译器日志选项)。

对于使用 mingw-make 问题进行人工构建,您首先必须使用“setup_h”构建目标运行命令行:

mingw32-make -f makefile.gcc setup_h other_options_of_your_command_line

完成后,您可以启动 Samea 命令行,而无需“setup_h”构建目标。

如果您不想浪费时间自己构建库(我知道这需要很长时间),您可以在这里找到我的预构建二进制文件。


0
投票
我可以给你一个解决MinGW32-make问题的方法。为了避免 CreateProcess 失败,请转到 Makefile.gcc 的末尾,您会发现类似以下内容: cmd=$(ComSpec) 将其更改为: cmd=C:\Windows\System3
© www.soinside.com 2019 - 2024. All rights reserved.