How to install libwxgtk3.0-dev to work with gtk3?
How to install libwxgtk3.0-dev to work with gtk3?
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.
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.
Re: How to install libwxgtk3.0-dev to work with gtk3?
Hi,
The unreliable way is to add a README to the source-code package.
Regards,
David
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/).I suspect the fact that the distributed version runs with gtk2 and the one from source with gtk3.
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?Am I on the right track?
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.How can I force or reinstall the distributed version to use gtk3?
The unreliable way is to add a README to the source-code package.
Regards,
David
Re: How to install libwxgtk3.0-dev to work with gtk3?
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".
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.
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 ()
Regards.
Last edited by DavidHart on Wed Dec 19, 2018 4:01 pm, edited 1 time in total.
Reason: Added code tags
Reason: Added code tags
Re: How to install libwxgtk3.0-dev to work with gtk3?
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:This is the backtrace of dbg.
Code: Select all
wx3.0.4-source-dir> mkdir build2 && cd build2 && \
../configure --with-gtk=2 --prefix=$(pwd) && make -j<whatever>
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.
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....if there is a way to force the lib that installs with apt-get to use gtk3 instead of gtk2?
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.
Re: How to install libwxgtk3.0-dev to work with gtk3?
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.
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.
Re: How to install libwxgtk3.0-dev to work with gtk3?
I'm not 100% sure I understand what you tried, but: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.
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.
Perhaps your Makefile needs some updating e.g. maybe it hardwires linking against a non-existent lib...If I build the 'image' sample with my Makefile the program crashes.
Re: How to install libwxgtk3.0-dev to work with gtk3?
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.
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);
}
Re: How to install libwxgtk3.0-dev to work with gtk3?
Hi,
Can you run the modified minimal under the gdb and give us a backtrace?
Thank you.
Can you run the modified minimal under the gdb and give us a backtrace?
Thank you.
Re: How to install libwxgtk3.0-dev to work with gtk3?
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.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.
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.
Re: How to install libwxgtk3.0-dev to work with gtk3?
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)
Re: How to install libwxgtk3.0-dev to work with gtk3?
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.
Re: How to install libwxgtk3.0-dev to work with gtk3?
Hi,
If you run:
you should see only __WXGTK{2}__ or __WXGTK3__, but not both.
Thank you.
Where exactly do you see this?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.
If you run:
Code: Select all
wx-config --cxxflags
Thank you.
Re: How to install libwxgtk3.0-dev to work with gtk3?
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.
The output of wx-config --cxxflags only contains -D__WXGTK__, no version number.
Re: How to install libwxgtk3.0-dev to work with gtk3?
Hi,
Is it with GTK2 or GTK3 build?
Thank you.
Is it with GTK2 or GTK3 build?
Thank you.
Re: How to install libwxgtk3.0-dev to work with gtk3?
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?
and 3 > 2.0
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?
Yes. If you look in setup.h it says e.g.I see that __WXGTK20__ is defined both for gtk2 and gtk3.
Code: Select all
/* Define this if your version of GTK+ is greater than 2.0 */
#define __WXGTK20__ 1
That's right.I will use __WXGTK3__ where I need to switch between versions.