2017-04-16 16 views
1

私の英語は申し訳ありません。
共有ライブラリ(qtライブラリとglibcライブラリとALLライブラリ)から依存関係のないQTアプリケーションを作成します。このためには、QTソースをダウンロードし、-staticオプションをつけてビルドし、すべての* .aライブラリをlddでチェックしてください。このライブラリは共有.so libからの依存関係はありません。新しいQTライブラリを/opt/Q5.8にインストールし、/opt/Q5.8/binを$ PATHに追加します。
次に、Hello Worldプロジェクトのテストを作成します。
メインの.cpp:Linuxで完全に静的なQTアプリケーションを構築するにはどうすればよいですか?

#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 

は、その後、私はqmakeの実行|作る。
qmakeのは、成功したMakefileを作成しますが、出力誤差を作る:私が間違って

[[email protected] 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 

何をしているのですか?

答えて

0

すべてのQtの依存関係には静的ライブラリがありません。最近のLinuxディストリビューションでは共有ライブラリしか提供していません。また、現在のglibcを静的にリンクすることもできません。

1

Qtをソースからダウンロードしてコンパイルし、静的フラグを渡して、独自の静的バイナリをビルドできるようにする必要があります。

これを実行すると、ターゲットマシンでqtライブラリを必要としないバイナリが作成されますが、基本QtCoreとQtGuiのバイナリは13 + MBになります。ダイナミックにリンクされたQt実行可能ファイルでより一般的な0.5 + MBです。

http://doc.qt.io/qt-5/configure-options.html

http://www.linuxfromscratch.org/blfs/view/8.0/x/qt5.html

適切なのconfigureを実行すると、コマンドを作成し、その後、...それを解凍します

http://download.qt.io/archive/qt/5.8/5.8.0/single/qt-everywhere-opensource-src-5.8.0.tar.xz

を、このようなダウンロードファイルを使用してください。

./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 

これを実行すると、一日中静的なQtプログラムを作成できます。

希望に役立ちます。

+0

私はそれをほぼ行います。私は、静的オプションでQTを構築します。しかし、私は-no-rpath、-skip qtwebengineオプションを指定しません。 glib-2.0や他の非QTライブラリを見つけることができないリンカの出力エラー –

+0

問題はQtではなく、リンクするlibsで問題になります。静的オプションを使用してQtをビルドすると、実行可能ファイルは静的Qtライブラリにのみリンクされますが、外部依存関係なしで実行されるQtビルドは生成されません。静的Qtライブラリは引き続き動的にサードパーティのライブラリにリンクします。したがって、OPにサードパーティの静的ライブラリがないため、リンカーに静的リンクを強制すると、エラーが発生します。 – dtech

関連する問題