From cef75b87bdbd307810a77f45e1f3b9152f2c5ac2 Mon Sep 17 00:00:00 2001 From: mappu Date: Tue, 3 Sep 2024 20:11:23 +1200 Subject: [PATCH] windows: add extra link libraries for static qwindows plugin --- README.md | 2 +- qt/cflags_windowsqtstatic.cpp | 6 ++++++ qt/cflags_windowsqtstatic.go | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 qt/cflags_windowsqtstatic.cpp create mode 100644 qt/cflags_windowsqtstatic.go diff --git a/README.md b/README.md index 2b00c3e..3527d4b 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,6 @@ Some C++ idioms that were difficult to project were omitted from the binding. Bu 1. Build the necessary docker container for cross-compilation: - `docker build -t miqt/win64-cross:latest -f win64-cross-go1.23-qt5.15-static.Dockerfile .` 2. Build your application: - - `docker run --rm -v $(pwd):/src -w /src miqt/win64-cross:latest go build -buildvcs=false -ldflags '-s -w -H windowsgui'` + - `docker run --rm -v $(pwd):/src -w /src miqt/win64-cross:latest go build -buildvcs=false --tags=windowsqtstatic -ldflags '-s -w -H windowsgui'` For repeated builds, the compile speed can be improved if you also bind-mount the Docker container's `GOCACHE` directory: `-v $(pwd)/container-build-cache:/root/.cache/go-build` diff --git a/qt/cflags_windowsqtstatic.cpp b/qt/cflags_windowsqtstatic.cpp new file mode 100644 index 0000000..6823592 --- /dev/null +++ b/qt/cflags_windowsqtstatic.cpp @@ -0,0 +1,6 @@ +#ifdef MIQT_WINDOWSQTSTATIC + +#include +Q_IMPORT_PLUGIN (QWindowsIntegrationPlugin); + +#endif \ No newline at end of file diff --git a/qt/cflags_windowsqtstatic.go b/qt/cflags_windowsqtstatic.go new file mode 100644 index 0000000..282ce3d --- /dev/null +++ b/qt/cflags_windowsqtstatic.go @@ -0,0 +1,17 @@ +//go:build windowsqtstatic +// +build windowsqtstatic + +package qt + +// Some extra libraries should be linked to make a proper static build. +// Otherwise, it can cause "No Qt platform plugin could be initialized" error. +// @ref https://github.com/mappu/miqt/issues/25 +// @ref https://stackoverflow.com/a/16776116 +// @ref https://stackoverflow.com/a/58648193 +// @ref https://stackoverflow.com/a/57374635 + +/* +#cgo windowsqtstatic CXXFLAGS: -DMIQT_WINDOWSQTSTATIC +#cgo LDFLAGS: -L/usr/lib/mxe/usr/x86_64-w64-mingw32.static/qt5/plugins/platforms -lqwindows -lQt5FontDatabaseSupport -lQt5EventDispatcherSupport -lQt5ThemeSupport -lQt5PlatformCompositorSupport -lQt5AccessibilitySupport -lQt5WindowsUIAutomationSupport -lwtsapi32 +*/ +import "C"