How can I build fully static QT application in Linux? - linux

Sorry for my English.
I want build QT application without dependencies from any shared libraries(qt libs and glibc and ALL libraries). For this I download QT sources, build it with -static option, check all *.a libraries by ldd. This libraries have not dependencies from shared .so lib. I install new QT libraries to /opt/Q5.8 and add /opt/Q5.8/bin to $PATH.
Then I create test Hello world project.
main .cpp:
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
cout << "Hello world!" << endl;
return 0;
}
main.pro:
CONFIG += debug console
SOURCES += main.cpp
QMAKE_LFLAGS += -static
Then I run qmake | make.
qmake create Makefile successful, but make output errors:
[oleg#reffum qt_static]$ make
g++ -static -o main main.o main_plugin_import.o -L/opt/Qt5.8/lib -L/opt/Qt5.8/plugins/platforms -lqwayland-egl -lwayland-egl -lqwayland-generic -lqwayland-xcomposite-egl -lqwayland-xcomposite-glx -lQt5WaylandClient -lXcomposite -lwayland-client -lwayland-cursor -lqxcb -L/opt/Qt5.8/plugins/xcbglintegrations -lqxcb-egl-integration -lqxcb-glx-integration -lQt5XcbQpa -lxcb-xinerama -lQt5LinuxAccessibilitySupport -lQt5AccessibilitySupport -lQt5GlxSupport -lXrender -lxcb-xkb -lxcb-sync -lxcb-xfixes -lxcb-randr -lxcb-image -lxcb-shm -lxcb-keysyms -lxcb-icccm -lxcb-shape -lxcb-glx -lXi -lSM -lICE -lxcb-render-util -lxcb-render -lxkbcommon-x11 -L/opt/Qt5.8/plugins/imageformats -lqgif -lqicns -lqico -lqjp2 -ljasper -lqjpeg -ljpeg -lqmng -lmng -lqtga -lqtiff -ltiff -lqwbmp -lqwebp -lwebp -lwebpdemux -L/opt/Qt5.8/plugins/egldeviceintegrations -lqeglfs-kms-egldevice-integration -lqeglfs-kms-integration -lQt5EglFsKmsSupport -lgbm -ldrm -lqeglfs-x11-integration -lQt5EglFSDeviceIntegration -lQt5EventDispatcherSupport -lQt5ServiceSupport -lQt5ThemeSupport -lQt5DBus -ldbus-1 -lQt5FontDatabaseSupport -lQt5FbSupport -lQt5EglSupport -lXext -lQt5PlatformCompositorSupport -lQt5InputSupport -lmtdev -linput -lxkbcommon -lQt5Gui -lpng16 -lharfbuzz -lQt5DeviceDiscoverySupport -ludev -lQt5Core -licui18n -licuuc -licudata -lm -ldl -lrt -lz -lpcre16 -lgthread-2.0 -lglib-2.0 -lxcb -lX11 -lX11-xcb -lfontconfig -lfreetype -lts -lEGL -lGL -lpthread
/usr/bin/ld: cannot find -lwayland-egl
/usr/bin/ld: cannot find -lXcomposite
/usr/bin/ld: cannot find -lwayland-client
/usr/bin/ld: cannot find -lwayland-cursor
/usr/bin/ld: cannot find -lxcb-xinerama
/usr/bin/ld: cannot find -lXrender
/usr/bin/ld: cannot find -lxcb-xkb
/usr/bin/ld: cannot find -lxcb-sync
/usr/bin/ld: cannot find -lxcb-xfixes
/usr/bin/ld: cannot find -lxcb-randr
/usr/bin/ld: cannot find -lxcb-image
/usr/bin/ld: cannot find -lxcb-shm
/usr/bin/ld: cannot find -lxcb-keysyms
/usr/bin/ld: cannot find -lxcb-icccm
/usr/bin/ld: cannot find -lxcb-shape
/usr/bin/ld: cannot find -lxcb-glx
/usr/bin/ld: cannot find -lXi
/usr/bin/ld: cannot find -lSM
/usr/bin/ld: cannot find -lICE
/usr/bin/ld: cannot find -lxcb-render-util
/usr/bin/ld: cannot find -lxcb-render
/usr/bin/ld: cannot find -lxkbcommon-x11
/usr/bin/ld: cannot find -ljpeg
/usr/bin/ld: cannot find -lmng
/usr/bin/ld: cannot find -ltiff
/usr/bin/ld: cannot find -lwebp
/usr/bin/ld: cannot find -lwebpdemux
/usr/bin/ld: cannot find -lgbm
/usr/bin/ld: cannot find -ldrm
/usr/bin/ld: cannot find -ldbus-1
/usr/bin/ld: cannot find -lXext
/usr/bin/ld: cannot find -lmtdev
/usr/bin/ld: cannot find -linput
/usr/bin/ld: cannot find -lxkbcommon
/usr/bin/ld: cannot find -lpng16
/usr/bin/ld: cannot find -lharfbuzz
/usr/bin/ld: cannot find -ludev
/usr/bin/ld: cannot find -licui18n
/usr/bin/ld: cannot find -licuuc
/usr/bin/ld: cannot find -licudata
/opt/Qt5.8/lib/libQt5Core.a(qlibrary_unix.o): In function `QLibraryPrivate::load_sys()':
qlibrary_unix.cpp:(.text+0x103a): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: cannot find -lpcre16
/usr/bin/ld: cannot find -lgthread-2.0
/usr/bin/ld: cannot find -lglib-2.0
/usr/bin/ld: cannot find -lxcb
/usr/bin/ld: cannot find -lX11
/usr/bin/ld: cannot find -lX11-xcb
/usr/bin/ld: cannot find -lfontconfig
/usr/bin/ld: cannot find -lfreetype
/usr/bin/ld: cannot find -lts
/usr/bin/ld: cannot find -lEGL
/usr/bin/ld: cannot find -lGL
collect2: error: ld returned 1 exit status
make: *** [Makefile:312: main] Error 1
What am I doing wrong?

You have to download and compile Qt from source and pass in the static flag to get it to let you build your own static binaries.
When you do this, you will have a binary that doesn't require qt libraries on the target machine, but your binary will be 13+MB for the basic QtCore and QtGui and more libraries built in... compared to the 0.5+MB that is more typical for a dynamically linked Qt executable.
http://doc.qt.io/qt-5/configure-options.html
http://www.linuxfromscratch.org/blfs/view/8.0/x/qt5.html
Use a download file like this...
http://download.qt.io/archive/qt/5.8/5.8.0/single/qt-everywhere-opensource-src-5.8.0.tar.xz
Untar it, then do an appropriate configure and make command.
./configure -prefix $QT5PREFIX \
-sysconfdir /etc/xdg \
-confirm-license \
-opensource \
-static #added this line \
-dbus-linked \
-openssl-linked \
-system-harfbuzz \
-system-sqlite \
-nomake examples \
-no-rpath \
-skip qtwebengine &&
make
After you do that, then you can build static Qt programs all day.
Hope that helps.

You are missing static libraries for all of Qt's dependences. Modern Linux distributions only provide shared libs. Also, you cannot statically link a current glibc.

Related

Compile errors (Ubuntu/CPP/FFMPEG)

Could not compile cpp file with various libs, all libs are actually contained in usr/lib/x86_64-linux-gnu, checked few times.
Please tell me how to amend the code to make it successfully compile
sh file:
g++ -Wno-format-zero-length -Wno-write-strings -L/home/supernova/Downloads/ffmpeg/lib/ -L/usr/lib/x86_64-linux-gnu/ -I/home/supernova/ffmpeg/include/ -o bin/ScreenRecorder src/main.cpp src/ScreenRecorder.cpp -lavdevice -lavfilter -lswscale -lavformat -lavcodec -lavutil -lswresample -lm -lva -lpthread -lvorbis -lvpx -lopus -lz -lpostproc -ldl -lfdk-aac -lmp3lame -lvorbisenc -lvorbisfile -lx264 -ltheora -lx265 -ltheoraenc -ltheoradec -ldl -lrt -lbz2 -lasound -lSDL -lSDLmain -lSDL_ttf -lfreetype -lass -llzma -lftgl -lperl -lcrypto -lxcb -lxcb-shm -lxcb-xfixes -lao -lxcb-shape -lfftw3 -lltdl
errors:
/usr/bin/ld: cannot find -lva
/usr/bin/ld: cannot find -lvorbis
/usr/bin/ld: cannot find -lvpx
/usr/bin/ld: cannot find -lopus
/usr/bin/ld: cannot find -lfdk-aac
/usr/bin/ld: cannot find -lmp3lame
/usr/bin/ld: cannot find -lvorbisenc
/usr/bin/ld: cannot find -lvorbisfile
/usr/bin/ld: cannot find -lx264
/usr/bin/ld: cannot find -ltheora
/usr/bin/ld: cannot find -lx265
/usr/bin/ld: cannot find -ltheoraenc
/usr/bin/ld: cannot find -ltheoradec
/usr/bin/ld: cannot find -lbz2
/usr/bin/ld: cannot find -lasound
/usr/bin/ld: cannot find -lSDL
/usr/bin/ld: cannot find -lSDLmain
/usr/bin/ld: cannot find -lSDL_ttf
/usr/bin/ld: cannot find -lass
/usr/bin/ld: cannot find -lftgl
/usr/bin/ld: cannot find -lxcb-xfixes
/usr/bin/ld: cannot find -lao
/usr/bin/ld: cannot find -lxcb-shape
/usr/bin/ld: cannot find -lfftw3

/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libQtCore.so when searching for -lQtCore

When I try to build a new project using Qt Creator, I get these errors:
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libQtGui.so when searching for -lQtGui
/usr/bin/ld: cannot find -lQtGui
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libQtCore.so when searching for -lQtCore
/usr/bin/ld: cannot find -lQtCore
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libpthread.so when searching for -lpthread
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libpthread.a when searching for -lpthread
collect2: error: ld returned 1 exit status
make: *** [untitled] Error 1
This is the command line from Compile Output:
g++ -m32 -o untitled main.o mainwindow.o moc_mainwindow.o -L/usr/lib/x86_64-linux-gnu -lQtGui -lQtCore -lpthread
It seems it is trying to build in 32-bit mode even though I'm on Ubuntu 64-bit.
I found the problem - my Qt Kits were all wrong. I had reinstalled Ubuntu recently, switching from 32-bit to 64-bit, but I had preserved my home folder, and I had a stale configuration at ~/.config/QtProject/. Deleting that folder fixed my problem and now Qt Creator builds projects fine.

Dependancies for RE2 on Centos7

I am trying to install re2 on a centos7 vm, and I am having some trouble solving these dependencies:
[root#roller re2]# make testinstall
cp testinstall.cc obj
(cd obj && g++ -I/usr/local/include -L/usr/local/lib testinstall.cc -lre2 -pthread -static -o testinstall)
/usr/bin/ld: cannot find -lstdc++
/usr/bin/ld: cannot find -lm
/usr/bin/ld: cannot find -lpthread
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
make: *** [testinstall] Error 1
Any help would be great! :)
thanks!

gfortran: compiling 32-bit executable in 64-bit system

I'm running Ubuntu 12.10 (64-bit), with Linux kernel 3.5.0-51-generic, on an AMD Athlon(tm) 64 X2 Dual Core Processor 5200+ ×2. I have GNU Fortran (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2.
I'm trying to compile some code into a 32-bit executable. I've checked that all the needed libraries are installed on my system (I ran ldd on a program previously compiled on a 32-bit computer, and downloaded the missing packages). I tried running $ gfortran foo.f -m32 -L/lib/i386-linux-gnu, but I get the following errors:
/usr/bin/ld: cannot find crt1.o: No such file or directory
/usr/bin/ld: cannot find crt1.o: No such file or directory
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgfortran.so when searching for -lgfortran
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgfortran.a when searching for -lgfortran
/usr/bin/ld: cannot find -lgfortran
/usr/bin/ld: cannot find -lm
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libquadmath.so when searching for -lquadmath
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libquadmath.a when searching for -lquadmath
/usr/bin/ld: cannot find -lquadmath
/usr/bin/ld: cannot find -lm
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: cannot find -lc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
/usr/bin/ld: cannot find crtn.o: No such file or directory
collect2: returned 1 exit status
I checked the /usr/lib/gcc/i686-linux-gnu/4.7 and /usr/lib/gcc/i686-linux-gnu/4.7.2 directories, and they are both empty.
Can you please help me solve this problem? I did my research but this was as far as I could get.
Thank you in advance!
The 64-bit libraries /usr/lib/gcc/x86_64-linux-gnu/... don't apply to your 32-bit compile. You need to install the multilib compiler packages (see https://help.ubuntu.com/community/InstallingCompilers). For example:
sudo apt-get install gfortran-multilib
Now gfortran -m32 foo.f should work.

/usr/bin/ld: skipping incompatible foo.so when searching for foo

I am using Ubuntu 13.10 64bit and I am getting the following errors while compiling the python wrappers of vlfeat library.
g++ -o _vlfeat.so ../../vl/aib.o ../../vl/generic.o ../../vl/hikmeans.o ../../vl/ikmeans.o ../../vl/imopv.o ../../vl/mathop.o ../../vl/pgm.o ../../vl/rodrigues.o ../../vl/stringop.o ../../vl/getopt_long.o ../../vl/host.o ../../vl/imop.o ../../vl/imopv_sse2.o ../../vl/mser.o ../../vl/random.o ../../vl/sift.o ../../vl/dsift.o mser/vl_erfill.o mser/vl_mser.o sift/vl_sift.o sift/vl_dsift.o sift/vl_siftdescriptor.o imop/vl_imsmooth.o misc/vl_binsum.o kmeans/vl_hikmeans.o kmeans/vl_ikmeans.o kmeans/vl_hikmeanspush.o kmeans/vl_ikmeanspush.o py_vlfeat.o -m64 -msse -m32 -msse -shared -lboost_python-mt-py27
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../libboost_python-mt-py27.so when searching for -lboost_python-mt-py27
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../libboost_python-mt-py27.a when searching for -lboost_python-mt-py27
/usr/bin/ld: skipping incompatible /usr/lib/libboost_python-mt-py27.so when searching for -lboost_python-mt-py27
/usr/bin/ld: skipping incompatible /usr/lib/libboost_python-mt-py27.a when searching for -lboost_python-mt-py27
/usr/bin/ld: cannot find -lboost_python-mt-py27
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libm.so when searching for -lm
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libm.a when searching for -lm
/usr/bin/ld: cannot find -lm
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libc.so when searching for -lc
/usr/bin/ld: skipping incompatible /usr/lib/x86_64-linux-gnu/libc.a when searching for -lc
/usr/bin/ld: cannot find -lc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status
make: *** [_vlfeat.so] Error 1
Any solutions to make this library work on 64 bit architecture?
remove -m32 in command line flags
to build with 32bit binary, you have to install
sudo apt-get install gcc-multilib and
sudo apt-get install ia32-libs-dev

Resources