I've been trying to create a wxWidgets C++ application under my EndeavourOS (should be arch linux at it's core).
My Desktop Environment is KDE Plasma (Wayland). But I the same problems occur on GNOME, and XFCE also.
I was already successful compiling a wxWidgets C++ application under Windows.
But on Linux, my compiled simple Program:
// 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);
...crashes:
./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.
This is the stacktrace I get with 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 ()
The strange thing is: the following code runs just fine (except that scaling the window sometimes hangs the program)
#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;
}
};
To build the library and the minimal sample:
cd wxWidgets
mkdir buildGTK
cd buildGTK
../configure --enable-debug --with-gtk && make -j4
cd samples/minimal
make
./minimal
That should build the library and minimal sample.
Let us know if you get any errors during this process.
Remember - this has to be done on the "clean emvironment" - no installed version of wxWidgets.
Then after everything is complete and you have the minimal sample running do:
g++ *.cpp -o test `/full/path/to/wx-config --cxxflags --libs`