I am trying to build statically linked binary for my app. I have a static build of Qt 5.5.1 and mesa 11.0.5 in my /opt and all needed static builds of libraries are in /usr.
First I was getting warnings about missing plugins when I run the app, so now I have this in cpp/plugins.cpp which is included from all.cpp:
#include <QtCore/QtPlugin>
Q_IMPORT_PLUGIN(QXcbIntegrationPlugin)
Q_IMPORT_PLUGIN(QXcbGlxIntegrationPlugin)
Q_IMPORT_PLUGIN(QXcbEglIntegrationPlugin)
Q_IMPORT_PLUGIN(QtQuick2Plugin)
Q_IMPORT_PLUGIN(QtQuickControlsPlugin)
Q_IMPORT_PLUGIN(QtQuick2DialogsPlugin)
Q_IMPORT_PLUGIN(QtQuickLayoutsPlugin)
Q_IMPORT_PLUGIN(QtQuick2WindowPlugin)
Q_IMPORT_PLUGIN(QmlSettingsPlugin)
Q_IMPORT_PLUGIN(QtQuick2PrivateWidgetsPlugin)
Q_IMPORT_PLUGIN(QJp2Plugin)
Q_IMPORT_PLUGIN(QEvdevKeyboardPlugin)
Q_IMPORT_PLUGIN(QEvdevMousePlugin)
build # QT_DEBUG_PLUGINS=1 LIBGL_DEBUG=verbose ./cbconvert-static
2015/11/18 14:11:49 log.go:88: .:0: QFactoryLoader::QFactoryLoader() ignoring "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3" since plugins are disabled in static builds
2015/11/18 14:11:49 log.go:88: .:0: loaded library "Xcursor"
2015/11/18 14:11:49 log.go:88: .:0: loaded library "Xcursor"
2015/11/18 14:11:49 log.go:88: .:0: QFactoryLoader::QFactoryLoader() ignoring "org.qt-project.Qt.QPA.Xcb.QXcbGlIntegrationFactoryInterface.5.5" since plugins are disabled in static builds
2015/11/18 14:11:49 log.go:88: .:0: QFactoryLoader::QFactoryLoader() ignoring "org.qt-project.Qt.QPA.QPlatformThemeFactoryInterface.5.1" since plugins are disabled in static builds
2015/11/18 14:11:49 log.go:88: .:0: QFactoryLoader::QFactoryLoader() ignoring "org.qt-project.Qt.QPlatformInputContextFactoryInterface.5.1" since plugins are disabled in static builds
2015/11/18 14:11:49 log.go:88: .:0: QFactoryLoader::QFactoryLoader() ignoring "org.qt-project.Qt.QStyleFactoryInterface" since plugins are disabled in static builds
2015/11/18 14:11:49 log.go:88: .:0: QFactoryLoader::QFactoryLoader() ignoring "org.qt-project.Qt.QIconEngineFactoryInterface" since plugins are disabled in static builds
2015/11/18 14:11:49 log.go:88: .:0: QFactoryLoader::QFactoryLoader() ignoring "org.qt-project.Qt.QImageIOHandlerFactoryInterface" since plugins are disabled in static builds
fatal error: unexpected signal during runtime execution
[signal 0xb code=0x1 addr=0x0 pc=0x16adcc7]
runtime.throw(0x277b220, 0x2a)
/home/milann/go/src/runtime/panic.go:527 +0x90
/home/milann/go/src/runtime/sigpanic_unix.go:12 +0x5a
goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x415190, 0xc820053cc0, 0xc800000000)
/home/milann/go/src/runtime/cgocall.go:120 +0x11b fp=0xc820053c90 sp=0xc820053c60
??:0 +0x36 fp=0xc820053cc0 sp=0xc820053c90
runtime.call32(0x0, 0x7ffea66fd518, 0x7ffea66fd5a7, 0x0)
/home/milann/go/src/runtime/asm_amd64.s:442 +0x3e fp=0xc820053d40 sp=0xc820053d18
/home/milann/go/src/runtime/cgocall.go:252 +0x10c fp=0xc820053d78 sp=0xc820053d40
/home/milann/go/src/runtime/cgocall.go:177 +0xd7 fp=0xc820053dd8 sp=0xc820053d78
runtime.cgocallback_gofunc(0x45e893, 0x414ff0, 0xc820053e40)
/home/milann/go/src/runtime/asm_amd64.s:799 +0x60 fp=0xc820053de8 sp=0xc820053dd8
runtime.asmcgocall(0x414ff0, 0xc820053e40)
/home/milann/go/src/runtime/asm_amd64.s:672 +0x3c fp=0xc820053df0 sp=0xc820053de8
runtime.cgocall(0x414ff0, 0xc820053e40, 0x0)
/home/milann/go/src/runtime/cgocall.go:121 +0x133 fp=0xc820053e20 sp=0xc820053df0
??:0 +0x31 fp=0xc820053e40 sp=0xc820053e20
/home/milann/Projects/cbconvert/gui/main.go:499 +0x2f fp=0xc820053f50 sp=0xc820053e98
/home/milann/go/src/runtime/proc.go:111 +0x2b0 fp=0xc820053fa0 sp=0xc820053f50
/home/milann/go/src/runtime/asm_amd64.s:1805 +0x1 fp=0xc820053fa8 sp=0xc820053fa0
goroutine 17 [syscall, locked to thread]:
/home/milann/go/src/runtime/asm_amd64.s:1805 +0x1
goroutine 5 [chan receive]:
/home/milann/Projects/cbconvert/gui/main.go:475 +0x1eb
Shared build works just fine. Qt is built with both EGL and GLX, mesa is built with swrast drivers and xlib-glx.
This is how I build app, I also changed some Qt pkgconfig files in order to link succesfully:
PKG_CONFIG_PATH=/opt/qt/lib/pkgconfig:/opt/mesa/lib/pkgconfig:/usr/lib/pkgconfig \
PKG_CONFIG_LIBDIR=/opt/qt/lib/pkgconfig:/opt/mesa/lib/pkgconfig:/usr/lib/pkgconfig \
CGO_LDFLAGS="-L/opt/qt/lib -L/opt/qt/plugins/generic -L/opt/qt/plugins/platforms -L/opt/qt/plugins/imageformats -L/opt/qt/qml/QtQuick.2 -L/opt/qt/qml/QtQuick/Controls -L/opt/qt/qml/QtQuick/Dialogs -L/opt/qt/qml/QtQuick/Layouts -L/opt/qt/qml/QtQuick/Window.2 -L/opt/qt/qml/Qt/labs/settings -L/opt/qt/qml/QtQuick/PrivateWidgets -L/opt/qt/plugins/xcbglintegrations" \
CGO_LDFLAGS="$CGO_LDFLAGS -lqxcb -lqtquick2plugin -lqtquickcontrolsplugin -ldialogplugin -lqquicklayoutsplugin -lwindowplugin -lqmlsettingsplugin -lwidgetsplugin -lqxcb-glx-integration -lqxcb-egl-integration -lqjp2 -lqevdevkeyboardplugin -lqevdevmouseplugin -ldl -lltdl -lfreetype -lm -lz -static-libgcc" \
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -v -x -o build/cbconvert-static --ldflags '-extldflags "-static"'