You are not logged in.

#1 2021-05-30 08:19:55

Blboun
Member
Registered: 2021-05-30
Posts: 10

WxWidgets and C++

Hi everyone, I've been using arch linux for about a month now and I wanted to get back to programming. I wanted to make some applications with wxwidgets and C++, so I installed wxwidgets, as they say on their site (https://wiki.wxwidgets.org/Compiling_an … ng_started), but since there was no installation process for Arch linux, I did everything as there was written, and it worked (of course, I changed gtk packages in installation to make it work, I installed GTK packages for Arch using pacman). Then I've tried to create a small program, so I did this

// wxWidgets "Hello World" Program
// For compilers that support precompilation, includes "wx/wx.h".
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif
class MyApp : public wxApp
{
public:
    virtual bool OnInit();
};
class MyFrame : public wxFrame
{
public:
    MyFrame();
private:
    void OnHello(wxCommandEvent& event);
    void OnExit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);
};
enum
{
    ID_Hello = 1
};
wxIMPLEMENT_APP(MyApp);
bool MyApp::OnInit()
{
    MyFrame *frame = new MyFrame();
    frame->Show(true);
    return true;
}
MyFrame::MyFrame()
    : wxFrame(NULL, wxID_ANY, "Hello World")
{
    wxMenu *menuFile = new wxMenu;
    menuFile->Append(ID_Hello, "&Hello...\tCtrl-H",
                     "Help string shown in status bar for this menu item");
    menuFile->AppendSeparator();
    menuFile->Append(wxID_EXIT);
    wxMenu *menuHelp = new wxMenu;
    menuHelp->Append(wxID_ABOUT);
    wxMenuBar *menuBar = new wxMenuBar;
    menuBar->Append(menuFile, "&File");
    menuBar->Append(menuHelp, "&Help");
    SetMenuBar( menuBar );
    CreateStatusBar();
    SetStatusText("Welcome to wxWidgets!");
    Bind(wxEVT_MENU, &MyFrame::OnHello, this, ID_Hello);
    Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT);
    Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT);
}
void MyFrame::OnExit(wxCommandEvent& event)
{
    Close(true);
}
void MyFrame::OnAbout(wxCommandEvent& event)
{
    wxMessageBox("This is a wxWidgets Hello World example",
                 "About Hello World", wxOK | wxICON_INFORMATION);
}
void MyFrame::OnHello(wxCommandEvent& event)
{
    wxLogMessage("Hello world from wxWidgets!");
}

(It's code from wxwidgets tutorial and hello world page)
and I built it like this

g++ *.cpp `wx-config --cxxflags --libs` -o simple

which worked and didn't error out. Then I tried to run it and it throw that error

./simple: error while loading shared libraries: libwx_gtk3u_xrc-3.1.so.5: cannot open shared object file: No such file or directory 

I tried locating that file and I found it here /usr/local/lib/libwx_gtk3u_xrc-3.1.so.5
(Don't know, if it is where it should be....)
I didn't setup *any* system variable

Does anyone know, what's wrong here and how to fix it ?

Offline

#2 2021-05-30 08:42:53

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,427

Re: WxWidgets and C++

If you really want /usr/local/lib to be considered you need to either set LD_LIBRARY_PATH=/usr/local/lib before executing your program or you need to add it to a .conf in  ld.so.conf.d and run ldconfig to have it be considered.

But was there a particular intention behind compiling wxwidgets yourself? the wxgtk3 package is something that exists

Offline

#3 2021-05-30 14:30:41

Blboun
Member
Registered: 2021-05-30
Posts: 10

Re: WxWidgets and C++

Thank you for your help, I didn't installed wxwidgets using Pacman, because I didn't knew it was right package, so I've tried what was on their page, and there was no mention of Arch Linux package. And now if I try it errors out.... (some files already existing and are owned by something....).
As you said, I tried to add  LD_LIBRARY_PATH=/usr/local/lib to my system variables. I added line

export  LD_LIBRARY_PATH=/usr/local/lib

to

/etc/profile

(hope this is right place) then I rebuilt my code, but the error is still here and it didn't changed....

V1del wrote:

you need to add it to a .conf in  ld.so.conf.d and run ldconfig to have it be considered.

About this option, well I don't know about that, so, how ? smile

Thanks

Offline

#4 2021-05-30 14:46:56

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,427

Re: WxWidgets and C++

You don't normally want to globally export LD_LIBRARY_PATH that way, do it explicitly when executing the program (i.e. LD_LIBRARY_PATH=/usr/local/lib ./simple) or just in the shell you are using. Also if you've added it in /etc/profile that would only be considered when you log in again. For the ld.so.conf.d way the "how" is pretty much what I described, create a text file e.g. /etc/ld.so.conf.d/usrlocal.conf add the path /usr/local/lib and run ldconfig as root.

But in any case if the only reason you compiled wxwidgets yourself is because you didn't know the Arch package name the most sustainable solution would be to remove your custom built wxwidgets and install the packaged version. You get files already existing errors precisely because you did install wxwidgets outside of the package manager.
.

Offline

#5 2021-05-30 14:54:18

Blboun
Member
Registered: 2021-05-30
Posts: 10

Re: WxWidgets and C++

Thank you so much, just deleted all files that my "Very professional installation process" created and installed wxgtk3, than re-login and Voilà now it's working

Offline

#6 2021-07-19 12:48:00

c0der1234
Member
Registered: 2021-07-14
Posts: 1

Re: WxWidgets and C++

I have the exact same problem. I installed wxgtk3, added /usr/local/lib to /etc/ld.so.conf.d/usrlocal.conf, and it still doesn't work. When i try to compile i get the message fatal error: wx/wx.h: No such file or directory.

Offline

#7 2021-07-19 14:51:41

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,447
Website

Re: WxWidgets and C++

If you have the same problem, perhaps you should try the same solution.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#8 2021-07-19 16:25:53

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,787
Website

Re: WxWidgets and C++


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

Board footer

Powered by FluxBB