static linking

754 views
Skip to first unread message

Milan Nikolic

unread,
Nov 18, 2015, 8:34:12 AM11/18/15
to go-qml
Hi,

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)

Final build is linked to these plugins but now it crashes:

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 stack:
runtime.throw(0x277b220, 0x2a)
/home/milann/go/src/runtime/panic.go:527 +0x90
runtime.sigpanic()
/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
/home/milann/golang/src/gopkg.in/qml.v1/qml.go:750 +0x46 fp=0xc820053ce8 sp=0xc820053cc0
/home/milann/golang/src/gopkg.in/qml.v1/bridge.go:190 +0x5d fp=0xc820053d18 sp=0xc820053ce8
runtime.call32(0x0, 0x7ffea66fd518, 0x7ffea66fd5a7, 0x0)
/home/milann/go/src/runtime/asm_amd64.s:442 +0x3e fp=0xc820053d40 sp=0xc820053d18
runtime.cgocallbackg1()
/home/milann/go/src/runtime/cgocall.go:252 +0x10c fp=0xc820053d78 sp=0xc820053d40
runtime.cgocallbackg()
/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/golang/src/gopkg.in/qml.v1/bridge.go:63 +0x16e fp=0xc820053e98 sp=0xc820053e40
main.main()
/home/milann/Projects/cbconvert/gui/main.go:499 +0x2f fp=0xc820053f50 sp=0xc820053e98
runtime.main()
/home/milann/go/src/runtime/proc.go:111 +0x2b0 fp=0xc820053fa0 sp=0xc820053f50
runtime.goexit()
/home/milann/go/src/runtime/asm_amd64.s:1805 +0x1 fp=0xc820053fa8 sp=0xc820053fa0

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
/home/milann/go/src/runtime/asm_amd64.s:1805 +0x1

goroutine 5 [chan receive]:
/home/milann/golang/src/gopkg.in/qml.v1/bridge.go:88 +0xd3
/home/milann/golang/src/gopkg.in/qml.v1/qml.go:751 +0x12c
main.run(0x0, 0x0)
/home/milann/Projects/cbconvert/gui/main.go:475 +0x1eb
/home/milann/golang/src/gopkg.in/qml.v1/bridge.go:60 +0x2d
/home/milann/golang/src/gopkg.in/qml.v1/bridge.go:62 +0x169

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"'

Does anyone have idea why it crashes or has done similar with go-qml? 

Milan Nikolic

unread,
Dec 2, 2015, 6:53:51 PM12/2/15
to go-qml
I managed to compile static binary for Windows, with qt compiled with -opengl desktop. For Linux I have binary that has most of the libs compiled statically but libGL and some X libraries are shared. 


I had to add this file in cpp/ and include it in all.cpp - https://gist.github.com/gen2brain/c0982e4533b6d9ee9358 . Also, I needed this patch so I can compile in all qml files in .exe  - https://github.com/go-qml/qml/pull/163 .
Reply all
Reply to author
Forward
0 new messages