wxWidgets 应用程序在 arch Linux 上崩溃,但在 Windows 上不会崩溃

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

我一直在尝试在我的 EndeavourOS 下创建一个 wxWidgets C++ 应用程序(其核心应该是 arch linux)。

我的桌面环境是 KDE Plasma (Wayland)。但我在 GNOME 和 XFCE 上也出现同样的问题。

我已经在 Windows 下成功编译了 wxWidgets C++ 应用程序。

但是在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); // it seems that this makes the program crash
        Center(); // and this also
    }
};

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)
// english translation: Memory access error (memory dump written)

Program terminated with signal SIGSEGV, Segmentation fault.

这是我使用 gdb 获得的堆栈跟踪:

User
(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;
    }
};
c++ linux wxwidgets archlinux
1个回答
0
投票

我同意可能存在 ODR 违规的分析。这很可能(使用此重现器)是由构建时的库版本与运行时的库版本冲突引起的。

在我的 NixOs 盒子上,我用一个简单的 nix-shell 构建了:

enter image description here

现在,NixOs 非常擅长分离依赖关系,但在常规 Linux 上,路径不会是唯一的,相反,您可能会看到类似

/usr/lib/x86_64/libwx_gtk...-.so
符号链接到特定版本的内容。如果这不是您要构建的版本,那么您将因 ODR 违规而面临 UB 的风险。

请注意,对于 Wx/GTK 版本来说,它并不“必须”。它可能是任何运行时链接器依赖项。

© www.soinside.com 2019 - 2024. All rights reserved.