Static Linking wxWidgets project for Linux Topic is solved

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.
Post Reply
Matthias_4242
In need of some credit
In need of some credit
Posts: 2
Joined: Tue Apr 03, 2018 7:23 pm

Static Linking wxWidgets project for Linux

Post by Matthias_4242 »

Hello everybody,

I am trying to distribute one self written programm and I want to make the installation as easy as possible. In first place I just used the default settings from code blocks and build the programm with shared object (ubuntu 14.04). When I checked whether the program could be started on another distribution (ubuntu 17.10), I found out that it does crash. From here started my journey to make a static link for linux which could be used on many system.

My actual progress is that far that I could compile wxwidgets again for static linking by using the following configuration

Code: Select all

./configure --prefix=/usr/local/i686-gcc --build=i686-linux --disable-shared --enable-unicode --enable-static
But when I try to compile the code I do receive a message about missing libs (libatk-v1.0 and libgdk_pixbuf-2.0). This is about codeblocks is showing me:

Code: Select all


-------------- Build: Release_static in Labskaus (compiler: GNU GCC Compiler)---------------

g++  -o bin/Release/Labskaus obj/Release/GUIFrame.o obj/Release/LabskausApp.o obj/Release/LabskausMain.o obj/Release/LabskausMain_Calibrate.o obj/Release/LabskausMain_Config.o obj/Release/LabskausMain_Settings.o obj/Release/LabskausMain_XMLList.o obj/Release/src/CCP_driver.o obj/Release/src/CCP_Frame.o obj/Release/src/CCP_Schedular_List_Element.o obj/Release/src/ECU_VarInfo.o obj/Release/src/ECU_VarLog.o obj/Release/src/LOG_Container.o obj/Release/src/rs232.o obj/Release/src/serial.o obj/Release/src/xmlECUfile.o obj/Release/tinyxml2.o  -static -L/usr/local/i686-gcc/lib -pthread   /usr/local/i686-gcc/lib/libwx_gtk2u_xrc-3.0.a /usr/local/i686-gcc/lib/libwx_gtk2u_qa-3.0.a /usr/local/i686-gcc/lib/libwx_baseu_net-3.0.a /usr/local/i686-gcc/lib/libwx_gtk2u_html-3.0.a /usr/local/i686-gcc/lib/libwx_gtk2u_adv-3.0.a /usr/local/i686-gcc/lib/libwx_gtk2u_core-3.0.a /usr/local/i686-gcc/lib/libwx_baseu_xml-3.0.a /usr/local/i686-gcc/lib/libwx_baseu-3.0.a -pthread -lgthread-2.0 -lX11 -lXxf86vm -lSM -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo -lpango-1.0 -lfontconfig -lgobject-2.0 -lglib-2.0 -lfreetype -lpng -ljpeg -lexpat -lwxregexu-3.0 -lwxtiff-3.0 -lz -ldl -lm   
/usr/bin/ld: cannot find -latk-1.0
/usr/bin/ld: cannot find -lgdk_pixbuf-2.0
/usr/local/i686-gcc/lib/libwx_baseu-3.0.a(baselib_dlunix.o): In function `wxDynamicLibrary::RawLoad(wxString const&, int)':
dlunix.cpp:(.text+0xa8): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libgio-2.0.a(libgio_2_0_la-glocalfileinfo.o): In function `lookup_gid_name':
(.text+0x10a7): warning: Using 'getgrgid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/local/i686-gcc/lib/libwx_baseu-3.0.a(baselib_utilsunx.o): In function `wxGetUserHome(wxString const&)':
utilsunx.cpp:(.text+0x1247): warning: Using 'getpwnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
obj/Release/LabskausMain_Config.o: In function `LabskausFrame::getDefaultDir()':
LabskausMain_Config.cpp:(.text+0x284b): warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libglib-2.0.a(libglib_2_0_la-gutils.o): In function `g_get_user_database_entry':
(.text+0xa4): warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libgio-2.0.a(libgio_2_0_la-glocalfileinfo.o): In function `lookup_uid_data':
(.text+0xf24): warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libX11.a(xim_trans.o): In function `_XimXTransSocketINETConnect':
(.text+0xdfe): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/local/i686-gcc/lib/libwx_baseu-3.0.a(baselib_utilsunx.o): In function `wxGetFullHostName(wchar_t*, int)':
utilsunx.cpp:(.text+0x4e2c): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libgio-2.0.a(libgio_2_0_la-gnetworkaddress.o): In function `g_network_address_parse':
(.text+0xbb9): warning: Using 'getservbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libgio-2.0.a(libgio_2_0_la-gnetworkaddress.o): In function `g_network_address_parse':
(.text+0xbd0): warning: Using 'endservent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
collect2: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
2 error(s), 10 warning(s) (0 minute(s), 0 second(s))
How can I solve the issue? and a more general question. Is this the correct way if I want to distribute a software for a lot of distributions?
DavidHart
Site Admin
Site Admin
Posts: 4252
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: Static Linking wxWidgets project for Linux

Post by DavidHart »

Hi,
How can I solve the issue?
and a more general question. Is this the correct way if I want to distribute a software for a lot of distributions?
The answer to the second question makes the first irrelevant :)

There is a reason why Linux distros each build their own programs: it works. Different distros, and different versions of the same distro, come with different versions of frequently used libraries which may not be ABI compatible with each other; and they aren't guaranteed to store them in the same places. So statically-linking wx to your program and expecting a single build to run on e.g. both ubuntu 14.04 and fedora 27 is doomed to failure. For one thing, the wx libs themselves depend on many system libs; which will be of different versions and stored in different locations.

The correct solution is to build your program separately for each target distro/version, linking dynamically against that distro/version's wx libs. Ideally you will also package your program in the standard way for that distro: deb for ubuntu/debian/mint, rpm for fedora/openSUSE etc. That has the additional advantage that the package will know that wx is a runtime dependency and insist on it being installed.

Regards,

David
Matthias_4242
In need of some credit
In need of some credit
Posts: 2
Joined: Tue Apr 03, 2018 7:23 pm

Re: Static Linking wxWidgets project for Linux

Post by Matthias_4242 »

Thanks for your detailed answer.

Actually that is worse than I expected. I hoped to maintain just two binaries. One for windows and one for Linux and now it looks like the maintance for linux might take much more time than I estimated. I will try to work out how to build a deb. file for my ubuntu14.04 maybe I can even create a ppa for this distro. Anyway, it is good to know that the approach of a static linux lib will fail anyway so that I can stop my investigations on how to do it.
Post Reply