1

I compiling my program in normal way.

mkdir mystatic

cd mystatic

make

g++ `./wx-config --static=yes --libs` `./wx-config --static=yes --cxxflags` etc

but when I type

ldd application I get many library.
    linux-gate.so.1 =>  (0xb76e7000)
    libgtk-x11-2.0.so.0 => /usr/lib/i386-linux-gnu/libgtk-x11-2.0.so.0 (0xb724b000)
    libgdk-x11-2.0.so.0 => /usr/lib/i386-linux-gnu/libgdk-x11-2.0.so.0 (0xb719d000)
    libpangocairo-1.0.so.0 => /usr/lib/i386-linux-gnu/libpangocairo-1.0.so.0 (0xb718f000)
    libgdk_pixbuf-2.0.so.0 => /usr/lib/i386-linux-gnu/libgdk_pixbuf-2.0.so.0 
....

How compiling my app staticaly. My app will be run on any Linux distribution.

  • try to set `-static` to `cflags` it will statically link all required library into single executable file – Shushant Mar 14 '14 at 13:41
  • $g++ -static -O3 -Wall `wx-config --static=yes --libs` `wx-config --static=yes --cxxflags` test.o showbuff.o -o test-static /usr/bin/ld: cannot find -latk-1.0 /usr/bin/ld: cannot find -lgdk_pixbuf-2.0 collect2: error: ld returned 1 exit status make: *** [test-static] Błąd 1 – user1972821 Mar 14 '14 at 13:44
  • In function `wxDynamicLibrary::GetProgramHandle()': dlunix.cpp:(.text+0x13): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/lib/gcc/i686-linux-gnu/4.8/../../../i386-linux-gnu/libgio-2.0.a(libgio_2_0_la-glocalfileinfo.o): In function `lookup_gid_name': (.text+0xf4c): warning: Using 'getgrgid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking – user1972821 Mar 14 '14 at 14:03

2 Answers2

2

At first I have reinstalled wxWdgets from sources (http://wxwidgets.org/downloads/) (like here http://ubuntuforums.org/showthread.php?t=937810):

./configure --enable-optimise --enable-stl --enable-unicode --enable-threads --enable-static --disable-shared --enable-monolithic --enable-graphics_ctx --with-x11

make
make install
update-alternatives --config wx-config
updatedb
locate wx_ | sed '/doc/d;/\/usr\/l/d'

To make wxWidgets-2.8.12/samples/minimal

I have modified 'Makefile' LIBS string:

LIBS = -lz -ldl -lm -lX11 -lcairo

Than command make

And I have got executable file "minimal" of 3164131 bytes

sdysdy
  • 21
  • 2
1

You really shouldn't link libc statically and in many cases you will have trouble with linking GTK+ libraries statically too (notice that this also has licensing implications). Instead, build the program on the oldest system you want to support (typically some ancient CentOS version), this works rather well in practice as all the other systems will have later, but compatible, versions of the libraries your program is linked with.

VZ.
  • 21,740
  • 3
  • 39
  • 42