You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Arch系Linux下wxWidgets应用崩溃求助(Windows运行正常)

wxWidgets在Arch Linux下编译运行崩溃排查

环境与问题

基于EndeavourOS(Arch Linux核心)开发wxWidgets C++应用,桌面环境为KDE Plasma(Wayland),该问题在GNOME、XFCE环境下同样存在。Windows平台编译运行wxWidgets程序正常,但Linux下编译特定代码后程序崩溃。

崩溃代码

编译命令:g++ main.cpp -o prog \wx-config --cppflags --libs``

#include <wx/wx.h>

class MyFrame: public wxFrame{
    public:
    MyFrame() : wxFrame(nullptr, wxID_ANY, "WxWidgets Linux Program") {
        wxPanel* mainPanel = new wxPanel(this);
        wxButton* cancel = new wxButton(mainPanel, wxID_ANY, "Cancel");
        SetClientSize(500, 50); // 疑似触发崩溃的代码
        Center(); // 同样疑似触发崩溃
    }
};

class App : public wxApp {
public:
    bool OnInit() {
        MyFrame* w = new MyFrame();
        w->Show();

        return true;
    }
};

wxIMPLEMENT_APP(App);

崩溃错误信息

./prog: /usr/lib/libwx_gtk3u_core-3.2.so.0: no version information available (required by ./prog)
./prog: /usr/lib/libwx_baseu-3.2.so.0: no version information available (required by ./prog)
./prog: Symbol `_ZTV8wxButton' has different size in shared object, consider re-linking
./prog: Symbol `_ZTV9wxControl' has different size in shared object, consider re-linking
./prog: Symbol `_ZTV12wxButtonBase' has different size in shared object, consider re-linking
./prog: Symbol `_ZTV11wxAnyButton' has different size in shared object, consider re-linking
./prog: Symbol `_ZTV11wxPanelBase' has different size in shared object, consider re-linking
./prog: Symbol `_ZTV7wxPanel' has different size in shared object, consider re-linking
./prog: Symbol `_ZTV17wxMDIClientWindow' has different size in shared object, consider re-linking
./prog: Symbol `_ZTV7wxFrame' has different size in shared object, consider re-linking
Speicherzugriffsfehler (Speicherabzug geschrieben)
// 英文翻译: Memory access error (memory dump written)

Program terminated with signal SIGSEGV, Segmentation fault.

GDB栈追踪信息

(gdb) bt
#0  0x00006e6f74747562 in ??? ()
#1  0x00007ffff7950f43 in wxWindow::PreCreation (this=this@entry=0x55555566ef80, parent=parent@entry=0x555555724500, pos=..., size=...) at /usr/src/debug/wxwidgets/wxWidgets-3.2.4/src/gtk/window.cpp:2953
#2  0x00007ffff79533f3 in wxWindow::Create (this=0x55555566ef80, parent=0x555555724500, id=-1, pos=..., size=..., style=2621440, name=...) at /usr/src/debug/wxwidgets/wxWidgets-3.2.4/src/gtk/window.cpp:2841
#3  0x00007ffff77abf16 in wxPanelBase::Create (this=0x55555566ef80, parent=<optimized out>, id=<optimized out>, pos=<optimized out>, size=<optimized out>, style=<optimized out>, name=...) at /usr/src/debug/wxwidgets/wxWidgets-3.2.4/src/common/panelcmn.cpp:98
#4  0x0000555555564da0 in wxPanel::wxPanel(wxWindow*, int, wxPoint const&, wxSize const&, long, wxString const&) ()
#5  0x0000555555565b84 in MyFrame::MyFrame() ()
#6  0x0000555555565da0 in App::OnInit() ()
#7  0x0000555555563e79 in wxAppConsoleBase::CallOnInit() ()
#8  0x00007ffff70f1452 in wxEntry (argc=<optimized out>, argv=<optimized out>) at /usr/src/debug/wxwidgets/wxWidgets-3.2.4/src/common/init.cpp:481
#9  0x000055555556354b in main ()

可正常运行的对比代码

#include <wx/wx.h>

class App : public wxApp {
public:
    bool OnInit() {
        
        wxFrame* window = new wxFrame(NULL, wxID_ANY, "GUI Test", wxDefaultPosition, wxSize(600, 400));
        wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
        wxStaticText* text = new wxStaticText(window, wxID_ANY, "Well Done!\nEverything seems to be working",
            wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE_HORIZONTAL);
        text->SetFont(wxFont(20, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
        sizer->Add(text);
        window->SetClientSize(300, 300);
        window->SetSizer(sizer);
        window->Show();
        return true;
    }
};

排查与解决步骤

从错误信息里的Symbol ... has different size in shared object可以明确,问题出在编译时链接的wxWidgets库与运行时加载的库版本/ABI不匹配,具体解决步骤:

  1. 检查当前wx-config指向的版本:
    运行wx-config --version,确认输出版本与系统安装的wxWidgets版本一致(栈追踪显示系统库为3.2.4)。
  2. 清理旧编译产物:
    删除之前生成的prog可执行文件,执行make clean(如果用Makefile),确保没有残留的旧目标文件。
  3. 重新编译时明确指定GTK3版本:
    由于Arch Linux的wxWidgets默认使用GTK3,编译命令改为:
    g++ main.cpp -o prog `wx-config --cppflags --libs gtk3`
    
  4. 排查是否混合了不同版本的wxWidgets:
    如果之前手动编译安装过wxWidgets,先卸载该版本,确保系统只保留通过包管理器安装的版本(比如pacman -S wxwidgets-gtk3)。
  5. 验证库路径:
    运行ldd prog查看程序链接的库路径,确认所有wx相关库都指向/usr/lib/下的系统库,而非自定义路径。

内容的提问来源于stack exchange,提问作者tbone

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 06:15:55