How to install libwxgtk3.0-dev to work with gtk3?

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
oscar1919
In need of some credit
In need of some credit
Posts: 9
Joined: Tue Dec 11, 2018 10:40 am
Location: Belgium

How to install libwxgtk3.0-dev to work with gtk3?

Postby oscar1919 » Wed Dec 19, 2018 11:22 am

Hi,

I am using Ubuntu 18.04. An application I have written crashes if I build it with wxWidgets-3.0.4, installed from distribution with sudo apt-get install libwxgtk3.0-dev. However, if I use a 3.0.4 built from source, the application runs fine. I suspect the fact that the distributed version runs with gtk2 and the one from source with gtk3.
See output of the wx-config commands below :
/usr/bin/wx-config --libs -->
-L/usr/lib/x86_64-linux-gnu -pthread -lwx_gtk2u_xrc-3.0 -lwx_gtk2u_html-3.0 -lwx_gtk2u_qa-3.0 -lwx_gtk2u_adv-3.0 -lwx_gtk2u_core-3.0 -lwx_baseu_xml-3.0 -lwx_baseu_net-3.0 -lwx_baseu-3.0
/usr/local/bin/wx-config --libs -->
-L/usr/local/lib -pthread -lwx_gtk3u_xrc-3.0 -lwx_gtk3u_html-3.0 -lwx_gtk3u_qa-3.0 -lwx_gtk3u_adv-3.0 -lwx_gtk3u_core-3.0 -lwx_baseu_xml-3.0 -lwx_baseu_net-3.0 -lwx_baseu-3.0
Am I on the right track? How can I force or reinstall the distributed version to use gtk3? Thanks in advance for any advice.

DavidHart
Site Admin
Site Admin
Posts: 3785
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: How to install libwxgtk3.0-dev to work with gtk3?

Postby DavidHart » Wed Dec 19, 2018 2:13 pm

Hi,
I suspect the fact that the distributed version runs with gtk2 and the one from source with gtk3.

Looking at the packages with synaptic, that's correct. There are gtk+2 packages e.g. libwxgtk3.0, and gtk+3 ones e.g. libwx3.0-gtk3 (another way to find out would be using https://packages.ubuntu.com/).
Am I on the right track?

There's no way to tell from what you've posted. What happens if you run the crashing program inside gdb? Is the backtrace helpful?

How can I force or reinstall the distributed version to use gtk3?

The reliable way is to distribute it as a deb; when you build the deb, have debian/control tell it that it 'Depends:' on libwx3.0-gtk3 etc, though the automatic dependency calculator should work it out anyway, and Build-Depends: on libwx3.0-gtk3-dev.
The unreliable way is to add a README to the source-code package.

Regards,

David

oscar1919
In need of some credit
In need of some credit
Posts: 9
Joined: Tue Dec 11, 2018 10:40 am
Location: Belgium

Re: How to install libwxgtk3.0-dev to work with gtk3?

Postby oscar1919 » Wed Dec 19, 2018 3:04 pm

Thanks for your comments, David.

This is the backtrace of dbg.

Reading symbols from ./pv...(no debugging symbols found)...done.
(gdb) run
Starting program: /home/jan/c/pv-3.2.0/exe/Linux64/pv pv
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Code: Select all

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff5662f19 in gdk_visual_get_best () from /usr/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0
(gdb) backtrace
#0  0x00007ffff5662f19 in gdk_visual_get_best () at /usr/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0
#1  0x00007ffff750fddd in wxApp::OnInitGui() () at /usr/lib/x86_64-linux-gnu/libwx_gtk2u_core-3.0.so.0
#2  0x00007ffff75103f9 in wxApp::Initialize(int&, wchar_t**) () at /usr/lib/x86_64-linux-gnu/libwx_gtk2u_core-3.0.so.0
#3  0x00007ffff6f3ba27 in wxEntryStart(int&, wchar_t**) () at /usr/local/lib/libwx_baseu-3.0.so.0
#4  0x00007ffff6f3bcbc in wxInitialize(int, wchar_t**) () at /usr/local/lib/libwx_baseu-3.0.so.0
#5  0x00007ffff6f3bd0d in wxEntry(int&, wchar_t**) () at /usr/local/lib/libwx_baseu-3.0.so.0
#6  0x000055555556cc02 in main ()


With respect to the last part of your answer, actually I would like to know if there is a way to force the lib that installs with apt-get to use gtk3 instead of gtk2? Or maybe that is a dumb question? I would prefer that my application does not need to replace available wx-3.0.4 libs.

Regards.
Last edited by DavidHart on Wed Dec 19, 2018 4:01 pm, edited 1 time in total.
Reason: Added code tags

DavidHart
Site Admin
Site Admin
Posts: 3785
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: How to install libwxgtk3.0-dev to work with gtk3?

Postby DavidHart » Wed Dec 19, 2018 4:23 pm

This is the backtrace of dbg.

Not very helpful, but adding the corresponding debug packages of the various wx ones might tell you more. Otherwise I suggest you make a 'local' gtk2 build:

Code: Select all

wx3.0.4-source-dir> mkdir build2 && cd build2 && \
../configure --with-gtk=2 --prefix=$(pwd) && make -j<whatever>

No need to 'make install'. Instead point to build2/ when you use that build. e.g. do
PATH=/full/path/to/that/build2:PATH
in the terminal before you build the program. Doing it that way allows multiple wx builds happily to co-exist and avoids messing with the installed ubuntu ones.
...if there is a way to force the lib that installs with apt-get to use gtk3 instead of gtk2?

What I wrote earlier is the only standard correct way to do that. The bad alternative would be to make a --disable-shared wx build and compile your program against that. The result would be that your program would be statically-linked to the wx libs. Of course there would be no guarantee that your program would run successfully on another ubuntu bionic install (there might be missing/conflicting system libs), less chance of it running on a different ubuntu release, and approximately none of it running on e.g. fedora. Which is why debs & rpms and other packaging types were invented.

A more modern, and arguably less bad, alternative would be to create and distribute a flatpak/snap/appimage instead. I've no experience of those.

oscar1919
In need of some credit
In need of some credit
Posts: 9
Joined: Tue Dec 11, 2018 10:40 am
Location: Belgium

Re: How to install libwxgtk3.0-dev to work with gtk3?

Postby oscar1919 » Thu Dec 20, 2018 8:30 am

Before taking any further steps, I did some tests with the samples coming along with wxWidgets-3.0.4. If I build the 'image' sample with my Makefile the program crashes. If I build it with the Makefile in the sample (but still using the not-local build lib), the sample runs ok.
However, I see in the output of make that the program is linked against gtk3, and not gtk2.
So, it seems that the make process coming along with the sample(s) does not use the output of wx-config --libs. Could this mean wx-config provides wrong information?

Meanwhile, I have built a local wxwidgets based on gtk2. My application crashes.

DavidHart
Site Admin
Site Admin
Posts: 3785
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: How to install libwxgtk3.0-dev to work with gtk3?

Postby DavidHart » Thu Dec 20, 2018 10:11 am

If I build the 'image' sample with my Makefile the program crashes. If I build it with the Makefile in the sample (but still using the not-local build lib), the sample runs ok.
However, I see in the output of make that the program is linked against gtk3, and not gtk2.

I'm not 100% sure I understand what you tried, but:
If you build wx3.0.4 from source, running configure and make, its samples too are configured by that 'configure'. So if you create a gtk+3 wx build, they will link to the wx_gtk3 libs.

If you install (on a debian-derived distro like ubuntu) a set of official wxWidgets packages, the examples come in one of those: wx3.0-examples. It installs to /usr/share/doc/wx-examples/ or similar. They aren't pre-build, but have makefiles. IIUC those samples do not come pre-configured, but build against whichever wx libs are in found in the $PATH.

If I build the 'image' sample with my Makefile the program crashes.

Perhaps your Makefile needs some updating e.g. maybe it hardwires linking against a non-existent lib...

oscar1919
In need of some credit
In need of some credit
Posts: 9
Joined: Tue Dec 11, 2018 10:40 am
Location: Belgium

Re: How to install libwxgtk3.0-dev to work with gtk3?

Postby oscar1919 » Thu Dec 20, 2018 1:53 pm

I have to apologize for making a wrong statement about the 'image' sample. It crashed because I ran the executable in another directory than the one which contains the image files.

Meanwhile, I could isolate the problem. It occurs in routine SetUseBestVisual(true). When adding the lines below to the minimal.cpp sample, the crash occurs for 4.0.3 based on gtk2.

Code: Select all

class MyApp : public wxApp
{
public:
    MyApp();
    virtual bool OnInit();
};

MyApp::MyApp() {

   SetUseBestVisual(true);
}

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 2834
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: How to install libwxgtk3.0-dev to work with gtk3?

Postby ONEEYEMAN » Thu Dec 20, 2018 4:08 pm

Hi,
Can you run the modified minimal under the gdb and give us a backtrace?

Thank you.

DavidHart
Site Admin
Site Admin
Posts: 3785
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: How to install libwxgtk3.0-dev to work with gtk3?

Postby DavidHart » Thu Dec 20, 2018 5:35 pm

Meanwhile, I could isolate the problem. It occurs in routine SetUseBestVisual(true). When adding the lines below to the minimal.cpp sample, the crash occurs for 4.0.3 based on gtk2.

Yes, I get the same thing, both with 3.0.4 and git HEAD. I tried debugging, but even with my gtk+2.24's debug symbol package installed it doesn't add anything useful.

Do you really need SetUseBestVisual()? If not, just remove it and see if your program now works on gtk2. Otherwise you can at least prevent the crash by defining it out: #if !defined(__WXGTK20__).

Ideally this should be reported on wxTrac, after first getting more information by making a debug gtk+2 build and building wx git HEAD against that. I'm afraid I don't have time/inclination to do that.

oscar1919
In need of some credit
In need of some credit
Posts: 9
Joined: Tue Dec 11, 2018 10:40 am
Location: Belgium

Re: How to install libwxgtk3.0-dev to work with gtk3?

Postby oscar1919 » Thu Dec 20, 2018 9:05 pm

This is the backtrace of the minimal example as requested.

Code: Select all

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff5e7bf19 in gdk_visual_get_best ()
   from /usr/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0
(gdb) backtrace
#0  0x00007ffff5e7bf19 in gdk_visual_get_best ()
    at /usr/lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0
#1  0x00007ffff778287d in wxApp::OnInitGui() ()
    at /home/jan/build/wxWidgets-3.0.4gtk2/lib/libwx_gtk2u_core-3.0.so.0
#2  0x00007ffff7782e79 in wxApp::Initialize(int&, wchar_t**) ()
    at /home/jan/build/wxWidgets-3.0.4gtk2/lib/libwx_gtk2u_core-3.0.so.0
#3  0x00007ffff7197a27 in wxEntryStart(int&, wchar_t**) ()
    at /home/jan/build/wxWidgets-3.0.4gtk2/lib/libwx_baseu-3.0.so.0
#4  0x00007ffff7197cbc in wxInitialize(int, wchar_t**) ()
    at /home/jan/build/wxWidgets-3.0.4gtk2/lib/libwx_baseu-3.0.so.0
#5  0x00007ffff7197d0d in wxEntry(int&, wchar_t**) ()
    at /home/jan/build/wxWidgets-3.0.4gtk2/lib/libwx_baseu-3.0.so.0
#6  0x000055555555e222 in main ()
(gdb)

oscar1919
In need of some credit
In need of some credit
Posts: 9
Joined: Tue Dec 11, 2018 10:40 am
Location: Belgium

Re: How to install libwxgtk3.0-dev to work with gtk3?

Postby oscar1919 » Fri Jan 04, 2019 3:04 pm

I see that __WXGTK20__ is defined both for gtk2 and gtk3. I will use __WXGTK3__ where I need to switch between versions. Thanks for the advice.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 2834
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: How to install libwxgtk3.0-dev to work with gtk3?

Postby ONEEYEMAN » Fri Jan 04, 2019 3:37 pm

Hi,
I see that __WXGTK20__ is defined both for gtk2 and gtk3. I will use __WXGTK3__ where I need to switch between versions. Thanks for the advice.


Where exactly do you see this?
If you run:

Code: Select all

wx-config --cxxflags


you should see only __WXGTK{2}__ or __WXGTK3__, but not both.

Thank you.

oscar1919
In need of some credit
In need of some credit
Posts: 9
Joined: Tue Dec 11, 2018 10:40 am
Location: Belgium

Re: How to install libwxgtk3.0-dev to work with gtk3?

Postby oscar1919 » Fri Jan 04, 2019 7:24 pm

It was in the #define section of the config.log(s), and I have written a small test program with some conditional prints.
The output of wx-config --cxxflags only contains -D__WXGTK__, no version number.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 2834
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: How to install libwxgtk3.0-dev to work with gtk3?

Postby ONEEYEMAN » Fri Jan 04, 2019 8:33 pm

Hi,
Is it with GTK2 or GTK3 build?

Thank you.

DavidHart
Site Admin
Site Admin
Posts: 3785
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: How to install libwxgtk3.0-dev to work with gtk3?

Postby DavidHart » Fri Jan 04, 2019 9:04 pm

It might help avoid confusion if I mention that, when testing
wx-config --cxxflags
in my debian wx3.1 builds,
the output always contains "-D__WXGTK__"
whether wx is built against gtk+2 or gtk+3.

Igor, which distro/version have you found where wx-config --cxxflags doesn't say just -D__WXGTK__ for a wxGTK build?

I see that __WXGTK20__ is defined both for gtk2 and gtk3.

Yes. If you look in setup.h it says e.g.

Code: Select all

/* Define this if your version of GTK+ is greater than 2.0 */
#define __WXGTK20__ 1

and 3 > 2.0
I will use __WXGTK3__ where I need to switch between versions.

That's right.


Return to “Compiler / Linking / IDE Related”

Who is online

Users browsing this forum: No registered users and 11 guests