Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows平台下用qt静态编译生成的Widgets应用程序报错 #356

Closed
jiagushuai opened this issue Feb 21, 2019 · 26 comments
Closed
Milestone

Comments

@jiagushuai
Copy link

jiagushuai commented Feb 21, 2019

  • Windows10下静态编译qt5.6.3
  • qt创建Widgets应用程序正常运行
    image
  • 用xmake的Widgets应用程序编译ok
D:\LING\Qt\widget>xmake -r -v
configure
{
    arch = x86
,   ld = link.exe
,   project = .
,   ccache = true
,   mode = release
,   qt_sdkver = 5.6.3
,   host = windows
,   plat = windows
,   cxx = cl.exe
,   kind = static
,   buildir = build
,   vs = 2015
,   qt = D:\QtStatic
}

[00%]: compiling.qt.ui src\mainwindow.ui
D:\QtStatic\5.6.3\VS2015Static\bin\uic.exe      src\mainwindow.ui -o build\.qt\ui\qt_demo\ui_mainwindow.h
[00%]: ccache compiling.release src\mainwindow.cpp
cl.exe -c -Ox -fp:fast -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtWidgets -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtGui -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtQml -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtNetwork -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtCore -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\mkspecs\\\\win32-msvc -ID:\\\\LING\\\\Qt\\\\widget\\\\build\\\\.qt\\\\ui\\\\qt_demo -DQT_NO_DEBUG -DQT_DEPRECATED_WARNINGS -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -D_WINDOWS -nologo -Fobuild\\.objs\\qt_demo\\windows\\x86\\release\\src\\mainwindow.cpp.obj src\\mainwindow.cpp
[25%]: ccache compiling.release src\main.cpp
cl.exe -c -Ox -fp:fast -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtWidgets -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtGui -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtQml -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtNetwork -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtCore -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\mkspecs\\\\win32-msvc -ID:\\\\LING\\\\Qt\\\\widget\\\\build\\\\.qt\\\\ui\\\\qt_demo -DQT_NO_DEBUG -DQT_DEPRECATED_WARNINGS -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -D_WINDOWS -nologo -Fobuild\\.objs\\qt_demo\\windows\\x86\\release\\src\\main.cpp.obj src\\main.cpp
[50%]: compiling.qt.moc src\mainwindow.h
D:\QtStatic\5.6.3\VS2015Static\bin\moc.exe      -DQT_NO_DEBUG -DQT_DEPRECATED_WARNINGS -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -D_WINDOWS -ID:\\QtStatic\\5.6.3\\VS2015Static\\include\\QtWidgets -ID:\\QtStatic\\5.6.3\\VS2015Static\\include\\QtGui -ID:\\QtStatic\\5.6.3\\VS2015Static\\include\\QtQml -ID:\\QtStatic\\5.6.3\\VS2015Static\\include\\QtNetwork -ID:\\QtStatic\\5.6.3\\VS2015Static\\include\\QtCore -ID:\\QtStatic\\5.6.3\\VS2015Static\\include -ID:\\QtStatic\\5.6.3\\VS2015Static\\mkspecs\\win32-msvc -ID:\\LING\\Qt\\widget\\build\\.qt\\ui\\qt_demo src\mainwindow.h -o build\.qt\moc\qt_demo\moc_mainwindow.cpp
cl.exe -c -Ox -fp:fast -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtWidgets -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtGui -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtQml -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtNetwork -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtCore -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\mkspecs\\\\win32-msvc -ID:\\\\LING\\\\Qt\\\\widget\\\\build\\\\.qt\\\\ui\\\\qt_demo -DQT_NO_DEBUG -DQT_DEPRECATED_WARNINGS -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -D_WINDOWS -nologo -Fobuild\\.objs\\qt_demo\\windows\\x86\\release\\build\\.qt\\moc\\qt_demo\\moc_mainwindow.cpp.obj build\\.qt\\moc\\qt_demo\\moc_mainwindow.cpp
[100%]: linking.release qt_demo.exe
link.exe -libpath:D:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\lib ws2_32.lib GDI32.lib ole32.lib ADVAPI32.lib SHELL32.lib USER32.lib qtpcre.lib OpenGL32.lib qtharfbuzzng.lib Qt5Widgets.lib Qt5Gui.lib Qt5Qml.lib Qt5Network.lib Qt5Core.lib -subsystem:windows -entry:mainCRTStartup -nologo -dynamicbase -nxcompat -machine:x86 -out:build\\windows\\x86\\release\\qt_demo.exe build\\.objs\\qt_demo\\windows\\x86\\release\\src\\mainwindow.cpp.obj build\\.objs\\qt_demo\\windows\\x86\\release\\src\\main.cpp.obj build\\.objs\\qt_demo\\windows\\x86\\release\\build\\.qt\\moc\\qt_demo\\moc_mainwindow.cpp.obj
build ok!
  • 但是运行报错
    image
@jiagushuai
Copy link
Author

  • Windows平台下尝试更新命令失败xmake update -v dev
D:\LING\Qt\widget>xmake update -v dev
xmake v2.2.2.201810162113, A cross-platform build utility based on Lua
Copyright (C) 2015-2018 Ruki Wang, tboox.org, xmake.io
Copyright (C) 2005-2015 Mike Pall, luajit.org
                         _
    __  ___ __  __  __ _| | ______
    \ \/ / |  \/  |/ _  | |/ / __ \
     >  <  | \__/ | /_| |   <  ___/
    /_/\_\_|_|  |_|\__ \|_|\_\____|
                         by ruki, tboox.org

      Manual: https://xmake.io/#/home
      Donate: https://xmake.io/pages/donation.html#donate


Usage: $xmake [task] [options] [target]

Build targets if no given tasks.

Actions:
       build             Build targets if no given tasks.
    c, clean             Remove all binary and temporary files.
    p, package           Package target.
    r, run               Run the project target.
    i, install           Package and install the target binary files.
       create            Create a new project.
    u, uninstall         Uninstall the project binary files.
    q, require           Install and update required packages.
    g, global            Configure the global options for xmake.
    f, config            Configure the project.

Plugins:
    l, lua               Run the lua script.
    m, macro             Run the given macro.
       doxygen           Generate the doxygen document.
       hello             Hello xmake!
       repo              Manage package repositories.
       project           Generate the project file.

Options:
    -q, --quiet                            Quiet operation.
    -y, --yes                              Input yes by default if need user confirm.
    -v, --verbose                          Print lots of verbose information.
        --root                             Allow to run xmake as root.
        --backtrace                        Print backtrace information for debugging.
        --profile                          Print performance data for debugging.
        --version                          Print the version number and exit.
    -h, --help                             Print this help message and exit.

    -F FILE, --file=FILE                   Read a given xmake.lua file.
    -P PROJECT, --project=PROJECT          Change to the given project directory.
                                           Search priority:
                                               1. The Given Command Argument
                                               2. The Envirnoment Variable: XMAKE_PROJECT_DIR
                                               3. The Current Directory

    -b, --build                            Build target. This is default building mode and optional.
    -r, --rebuild                          Rebuild the target.
    -a, --all                              Build all targets.

    -j JOBS, --jobs=JOBS                   Specifies the number of jobs to build simultaneously.
                                           (default: 4)
    -w, --warning                          Enable the warnings output.
    -t, --try                              Try building project using third-party buildsystem.

    target                                 Build the given target.
error: invalid task: update

@waruqi
Copy link
Member

waruqi commented Feb 21, 2019

windows下你这版本太老,需要先安装一次master/dev版本,才支持update命令。你也可以到github releases上下载 xmake-dev.exe/xmake-master.exe来更新

不过我还没更新刚的修改到xmake-dev.exe,等晚上我更新下。。

@jiagushuai
Copy link
Author

jiagushuai commented Feb 21, 2019

嗯嗯 那关于编译完不能运行的问题 跟更新版本有关系吗

@waruqi
Copy link
Member

waruqi commented Feb 21, 2019

windows下我之前测过动态库版本是可以运行的,你这static qt sdk的运行不起来 我这暂时没环境测试验证

暂时不清楚原因,看着像是运行时候的某些plugin在path下没找到导致,可能是运行环境的问题

你qt那个是通过qtcreator 运行的,还是手动点击程序运行的?qtcreator运行有可能会自动加载一些path环境什么的,跟xmake run的不一致。。

xmake编译那个,你是xmake run运行的,还是手动点击运行的?

你可以都尝试手动点击程序运行试试

@jiagushuai
Copy link
Author

我之前生成的动态库可以运行过,但是现在生成的不行了。

都是手动点击程序运行

  • qt那个是通过qtcreator编译,然后我放在xp裸机上双击可以运行
  • xmake编译那个在本机编译后手动点击运行就报错

@waruqi
Copy link
Member

waruqi commented Feb 21, 2019

那就你用 qt 编译,把完整的 编译、链接参数命令 什么的,贴一下,然后把xmake -v 编译的完整参数命令也贴一下

我对比下,看看 缺哪些flags

@jiagushuai
Copy link
Author

jiagushuai commented Feb 21, 2019

qt项目

  • pro配置文件

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = static
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui

  • 编译
16:14:48: 为项目static执行步骤 ...
16:14:48: 正在启动 "D:\QtStatic\5.6.3\VS2015Static\bin\qmake.exe" D:\LING\Qt\static\static.pro -r -spec win32-msvc2015 "CONFIG+=release"

16:14:48: 进程"D:\QtStatic\5.6.3\VS2015Static\bin\qmake.exe"正常退出。
16:14:48: 正在启动 "C:\Qt\Qt5.6.3\Tools\QtCreator\bin\jom.exe" 

	C:\Qt\Qt5.6.3\Tools\QtCreator\bin\jom.exe -f Makefile.Release
	D:\QtStatic\5.6.3\VS2015Static\bin\uic.exe ..\static\mainwindow.ui -o ui_mainwindow.h
	cl -c -nologo -Zc:wchar_t -FS -Zc:strictStrings -Zc:throwingNew -O2 -MT -GR -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc -DUNICODE -DWIN32 -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DNDEBUG -I..\static -I. -I..\..\..\QtStatic\5.6.3\VS2015Static\include -I..\..\..\QtStatic\5.6.3\VS2015Static\include\QtWidgets -I..\..\..\QtStatic\5.6.3\VS2015Static\include\QtGui -I..\..\..\QtStatic\5.6.3\VS2015Static\include\QtCore -Irelease -I. -I..\..\..\QtStatic\5.6.3\VS2015Static\mkspecs\win32-msvc2015 -Forelease\ @C:\Users\Administrator\AppData\Local\Temp\main.obj.14260.31.jom
main.cpp
	cl -c -nologo -Zc:wchar_t -FS -Zc:strictStrings -Zc:throwingNew -O2 -MT -GR -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc -DUNICODE -DWIN32 -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DNDEBUG -I..\static -I. -I..\..\..\QtStatic\5.6.3\VS2015Static\include -I..\..\..\QtStatic\5.6.3\VS2015Static\include\QtWidgets -I..\..\..\QtStatic\5.6.3\VS2015Static\include\QtGui -I..\..\..\QtStatic\5.6.3\VS2015Static\include\QtCore -Irelease -I. -I..\..\..\QtStatic\5.6.3\VS2015Static\mkspecs\win32-msvc2015 -Forelease\ @C:\Users\Administrator\AppData\Local\Temp\static_plugin_import.obj.14260.47.jom
	D:\QtStatic\5.6.3\VS2015Static\bin\moc.exe -DUNICODE -DWIN32 -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DNDEBUG -D_MSC_VER=1900 -D_WIN32 -ID:/QtStatic/5.6.3/VS2015Static/mkspecs/win32-msvc2015 -ID:/LING/Qt/static -ID:/QtStatic/5.6.3/VS2015Static/include -ID:/QtStatic/5.6.3/VS2015Static/include/QtWidgets -ID:/QtStatic/5.6.3/VS2015Static/include/QtGui -ID:/QtStatic/5.6.3/VS2015Static/include/QtCore -I. ..\static\mainwindow.h -o release\moc_mainwindow.cpp
static_plugin_import.cpp
	cl -c -nologo -Zc:wchar_t -FS -Zc:strictStrings -Zc:throwingNew -O2 -MT -GR -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc -DUNICODE -DWIN32 -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DNDEBUG -I..\static -I. -I..\..\..\QtStatic\5.6.3\VS2015Static\include -I..\..\..\QtStatic\5.6.3\VS2015Static\include\QtWidgets -I..\..\..\QtStatic\5.6.3\VS2015Static\include\QtGui -I..\..\..\QtStatic\5.6.3\VS2015Static\include\QtCore -Irelease -I. -I..\..\..\QtStatic\5.6.3\VS2015Static\mkspecs\win32-msvc2015 -Forelease\ @C:\Users\Administrator\AppData\Local\Temp\mainwindow.obj.14260.109.jom
mainwindow.cpp
	cl -c -nologo -Zc:wchar_t -FS -Zc:strictStrings -Zc:throwingNew -O2 -MT -GR -W3 -w34100 -w34189 -w44996 -w44456 -w44457 -w44458 -wd4577 -wd4467 -EHsc -DUNICODE -DWIN32 -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DNDEBUG -I..\static -I. -I..\..\..\QtStatic\5.6.3\VS2015Static\include -I..\..\..\QtStatic\5.6.3\VS2015Static\include\QtWidgets -I..\..\..\QtStatic\5.6.3\VS2015Static\include\QtGui -I..\..\..\QtStatic\5.6.3\VS2015Static\include\QtCore -Irelease -I. -I..\..\..\QtStatic\5.6.3\VS2015Static\mkspecs\win32-msvc2015 -Forelease\ @C:\Users\Administrator\AppData\Local\Temp\moc_mainwindow.obj.14260.953.jom
moc_mainwindow.cpp
	link /NOLOGO /DYNAMICBASE /NXCOMPAT /INCREMENTAL:NO /SUBSYSTEM:WINDOWS,5.01 "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:release\static.exe @C:\Users\Administrator\AppData\Local\Temp\static.exe.14260.1656.jom
16:14:51: 进程"C:\Qt\Qt5.6.3\Tools\QtCreator\bin\jom.exe"正常退出。
16:14:51: Elapsed time: 00:04.

xmake的编译参数

D:\LING\Qt\widget>xmake -r -v
configure
{
    arch = x86
    ccache = true
    cxx = cl.exe
    ld = link.exe
    mode = release
    qt_sdkver = 5.6.3
    host = windows
    plat = windows
    project = .
    kind = static
    buildir = build
    vs = 2015
    qt = D:\QtStatic
}
[  0%]: compiling.qt.ui src\mainwindow.ui
D:\QtStatic\5.6.3\VS2015Static\bin\uic.exe      src\mainwindow.ui -o build\.qt\ui\qt_demo\ui_mainwindow.h
[  0%]: ccache compiling.release src\mainwindow.cpp
cl.exe -c -Ox -fp:fast -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtWidgets -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtGui -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtQml -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtNetwork -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtCore -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\mkspecs\\\\win32-msvc -ID:\\\\LING\\\\Qt\\\\widget\\\\build\\\\.qt\\\\ui\\\\qt_demo -DQT_NO_DEBUG -DQT_DEPRECATED_WARNINGS -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -D_WINDOWS -nologo -Fobuild\\.objs\\qt_demo\\windows\\x86\\release\\src\\mainwindow.cpp.obj src\\mainwindow.cpp
[ 25%]: ccache compiling.release src\main.cpp
cl.exe -c -Ox -fp:fast -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtWidgets -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtGui -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtQml -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtNetwork -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtCore -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\mkspecs\\\\win32-msvc -ID:\\\\LING\\\\Qt\\\\widget\\\\build\\\\.qt\\\\ui\\\\qt_demo -DQT_NO_DEBUG -DQT_DEPRECATED_WARNINGS -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -D_WINDOWS -nologo -Fobuild\\.objs\\qt_demo\\windows\\x86\\release\\src\\main.cpp.obj src\\main.cpp
[ 50%]: compiling.qt.moc src\mainwindow.h
D:\QtStatic\5.6.3\VS2015Static\bin\moc.exe      -DQT_NO_DEBUG -DQT_DEPRECATED_WARNINGS -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -D_WINDOWS -ID:\\QtStatic\\5.6.3\\VS2015Static\\include\\QtWidgets -ID:\\QtStatic\\5.6.3\\VS2015Static\\include\\QtGui -ID:\\QtStatic\\5.6.3\\VS2015Static\\include\\QtQml -ID:\\QtStatic\\5.6.3\\VS2015Static\\include\\QtNetwork -ID:\\QtStatic\\5.6.3\\VS2015Static\\include\\QtCore -ID:\\QtStatic\\5.6.3\\VS2015Static\\include -ID:\\QtStatic\\5.6.3\\VS2015Static\\mkspecs\\win32-msvc -ID:\\LING\\Qt\\widget\\build\\.qt\\ui\\qt_demo src\mainwindow.h -o build\.qt\moc\qt_demo\moc_mainwindow.cpp
cl.exe -c -Ox -fp:fast -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtWidgets -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtGui -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtQml -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtNetwork -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtCore -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\mkspecs\\\\win32-msvc -ID:\\\\LING\\\\Qt\\\\widget\\\\build\\\\.qt\\\\ui\\\\qt_demo -DQT_NO_DEBUG -DQT_DEPRECATED_WARNINGS -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -D_WINDOWS -nologo -Fobuild\\.objs\\qt_demo\\windows\\x86\\release\\build\\.qt\\moc\\qt_demo\\moc_mainwindow.cpp.obj build\\.qt\\moc\\qt_demo\\moc_mainwindow.cpp
[100%]: linking.release qt_demo.exe
link.exe -libpath:D:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\lib ws2_32.lib GDI32.lib ole32.lib ADVAPI32.lib SHELL32.lib USER32.lib qtpcre.lib OpenGL32.lib qtharfbuzzng.lib Qt5Widgets.lib Qt5Gui.lib Qt5Qml.lib Qt5Network.lib Qt5Core.lib -subsystem:windows -entry:mainCRTStartup -nologo -dynamicbase -nxcompat -machine:x86 -out:build\\windows\\x86\\release\\qt_demo.exe build\\.objs\\qt_demo\\windows\\x86\\release\\src\\mainwindow.cpp.obj build\\.objs\\qt_demo\\windows\\x86\\release\\src\\main.cpp.obj build\\.objs\\qt_demo\\windows\\x86\\release\\build\\.qt\\moc\\qt_demo\\moc_mainwindow.cpp.obj
build ok!

@waruqi waruqi added this to the v2.2.5 milestone Feb 21, 2019
@jiagushuai
Copy link
Author

mac上使用静态编译的qt也出现 编译通过但是运行报错的情况

gushuai:sdSocketkey_mac_win jl$ cd ~/Desktop/Qt/widgetapp/
gushuai:widgetapp jl$ xmake -r -v
checking for the Xcode directory ... /Applications/Xcode.app
checking for the SDK version of Xcode ... 10.13
checking for the Qt SDK directory ... /Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64
checking for the Qt SDK version ... 5.7.1
configure
{
    ccache = true
    plat = macosx
    buildir = build
    arch = x86_64
    target_minver = 10.13
    xcode = /Applications/Xcode.app
    mode = release
    clean = true
    qt_sdkver = 5.7.1
    cxx = xcrun -sdk macosx clang
    theme = default
    project = .
    kind = static
    host = macosx
    xcode_sdkver = 10.13
    ld = xcrun -sdk macosx clang++
    qt = /Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64
}
checking for the ccache ... no
[  0%]: compiling.qt.ui src/mainwindow.ui
/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/bin/uic	src/mainwindow.ui -o build/.qt/ui/qt_demo/ui_mainwindow.h
checking for the xcrun -sdk macosx clang ... ok
checking for the flags (-O3) ... ok
checking for the flags (-fPIC) ... ok
[ 25%]: compiling.release src/mainwindow.cpp
"xcrun -sdk macosx clang" -c -fvisibility=hidden -O3 -std=c++11 -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/include/QtWidgets -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/include/QtGui -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/include/QtQml -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/include/QtNetwork -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/include/QtCore -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/include -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/mkspecs/macx-clang -I/Users/shandikeji/Desktop/Qt/widgetapp/build/.qt/ui/qt_demo -DQT_NO_DEBUG -DQT_DEPRECATED_WARNINGS -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -framework CoreFoundation -framework CoreGraphics -framework Carbon -framework Cocoa -framework DiskArbitration -framework IOKit -fPIC -Qunused-arguments -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -o build/.objs/qt_demo/macosx/x86_64/release/src/mainwindow.cpp.o src/mainwindow.cpp
checking for the flags (-H) ... ok
[  0%]: compiling.release src/main.cpp
"xcrun -sdk macosx clang" -c -fvisibility=hidden -O3 -std=c++11 -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/include/QtWidgets -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/include/QtGui -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/include/QtQml -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/include/QtNetwork -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/include/QtCore -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/include -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/mkspecs/macx-clang -I/Users/shandikeji/Desktop/Qt/widgetapp/build/.qt/ui/qt_demo -DQT_NO_DEBUG -DQT_DEPRECATED_WARNINGS -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -framework CoreFoundation -framework CoreGraphics -framework Carbon -framework Cocoa -framework DiskArbitration -framework IOKit -fPIC -Qunused-arguments -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -o build/.objs/qt_demo/macosx/x86_64/release/src/main.cpp.o src/main.cpp
[ 50%]: compiling.qt.moc src/mainwindow.h
/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/bin/moc	-DQT_NO_DEBUG -DQT_DEPRECATED_WARNINGS -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/include/QtWidgets -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/include/QtGui -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/include/QtQml -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/include/QtNetwork -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/include/QtCore -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/include -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/mkspecs/macx-clang -I/Users/shandikeji/Desktop/Qt/widgetapp/build/.qt/ui/qt_demo src/mainwindow.h -o build/.qt/moc/qt_demo/moc_mainwindow.cpp
"xcrun -sdk macosx clang" -c -fvisibility=hidden -O3 -std=c++11 -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/include/QtWidgets -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/include/QtGui -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/include/QtQml -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/include/QtNetwork -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/include/QtCore -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/include -I/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/mkspecs/macx-clang -I/Users/shandikeji/Desktop/Qt/widgetapp/build/.qt/ui/qt_demo -DQT_NO_DEBUG -DQT_DEPRECATED_WARNINGS -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -framework CoreFoundation -framework CoreGraphics -framework Carbon -framework Cocoa -framework DiskArbitration -framework IOKit -fPIC -Qunused-arguments -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -o build/.objs/qt_demo/macosx/x86_64/release/build/.qt/moc/qt_demo/moc_mainwindow.cpp.o build/.qt/moc/qt_demo/moc_mainwindow.cpp
checking for the xcrun -sdk macosx clang++ ... ok
checking for the flags (-Wl,-rpath=/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/lib) ... no
checking for the flags (-Xlinker -rpath -Xlinker /Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/lib) ... ok
[100%]: linking.release qt_demo
"xcrun -sdk macosx clang++" -o build/macosx/x86_64/release/qt_demo build/.objs/qt_demo/macosx/x86_64/release/src/main.cpp.o build/.objs/qt_demo/macosx/x86_64/release/src/mainwindow.cpp.o build/.objs/qt_demo/macosx/x86_64/release/build/.qt/moc/qt_demo/moc_mainwindow.cpp.o -L/Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/lib -Xlinker -rpath -Xlinker /Users/shandikeji/Qt/qt5.7.1/5.7.1/clang_64/lib -Wl,-x -fvisibility=hidden -lqtpcre -lqtharfbuzzng -lqtpng -lQt5Widgets -lQt5Gui -lQt5Qml -lQt5Network -lQt5Core -framework CoreFoundation -framework CoreGraphics -framework Carbon -framework Cocoa -framework DiskArbitration -framework IOKit -lz
build ok!👌
gushuai:widgetapp jl$ xmake run
This application failed to start because it could not find or load the Qt platform plugin "cocoa"
in "".

Reinstalling the application may fix this problem.
error: execv(/Users/shandikeji/Desktop/Qt/widgetapp/build/macosx/x86_64/release/qt_demo) failed(-1)!

@waruqi
Copy link
Member

waruqi commented Feb 21, 2019

如果两个平台都有相同的问题,应该不是link的差异导致,可能是某些编译flags确实导致, 或者mainwindow.h 生成moc_mainwindow.cpp上,一些flags有差异。。

这块 我晚上或者明天细看下,你这也可以自己 对比下 跟qt的flags差别,自己通过 add_cxflags 追加尝试下。。

或者可以吧 qt生成的 moc_mainwindow.cpp 替换xmake生成的 moc_mainwindow.cpp 尝试编译试试,看看是不是moc生成的问题。。

再或者把你这mac下 static qt sdk的环境打包一份。。发我下。。我回头看看

@waruqi
Copy link
Member

waruqi commented Feb 21, 2019

	link /NOLOGO /DYNAMICBASE /NXCOMPAT /INCREMENTAL:NO /SUBSYSTEM:WINDOWS,5.01 "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /MANIFEST:embed /OUT:release\static.exe @C:\Users\Administrator\AppData\Local\Temp\static.exe.14260.1656.jom

qt编译的这个C:\Users\Administrator\AppData\Local\Temp\static.exe.14260.1656.jom里面的完整link参数能给我看下么?

还有mac下也不行,那mac下qt编译的完整参数能帖我看下么。。我对比下。。

目前我查了下,可能还是link的时候,xmake 没有吧qt plugin的库加进去,导致加载失败了。。所以我要对比下,qt编译的link参数。。

目前你提供的看不到qt的完整link参数,很多都在.jom文件里

@waruqi
Copy link
Member

waruqi commented Feb 21, 2019

关于这个问题的一些资料:

https://stackoverflow.com/questions/25188153/this-application-failed-to-start-because-it-could-not-find-or-load-the-qt-platfo

https://codeday.me/bug/20171015/85121.html

里面最下面说到另外一种解决办法就是设置环境变量来禁用插件

@waruqi
Copy link
Member

waruqi commented Feb 21, 2019

https://forum.qt.io/topic/90293/could-not-find-or-load-the-qt-platform-plugin-windows-in/8

这里有对windows上你这个问题的解决方式

Open cmd and type echo %QT_PLUGIN_PATH% if it's not empty then delete it (just google: delete environmental variable windows #, where # is your windows version)

Open cmd and type echo %PATH% and press enter. You'll see a list separated by ; of folder paths. Go line by line and make sure they do not point to a folder that contains a platforms folder that has qwindows.dll in it. If you find such a path edit the PATH variable and remove it (just google: edit environmental variable windows #, where # is your windows version)

这人就是通过移除所有插件相关path环境变量来解决的。

Hi VRonin,

I followed your steps and looked up the environmental variable. It turns out that the %Qt_Plugin_path% was indeed set by a certain program (numerical model) which I had installed. I deleted the variable and rebooted the system. As a result all the programs were functioning again without errors.

Considered this solved. Thanks a lot!

@waruqi
Copy link
Member

waruqi commented Feb 21, 2019

http://www.voidcn.com/article/p-flhmawej-bcy.html

这里是另一个解决方式,是吧qt相关插件目录放到exe执行目录下,让其找到来解决。。

所以我现在怀疑,应该不是编译的问题,还是运行的环境问题,mac下说不定可以通过编译的时候加上额外的rpathdir来让其找到,但是Windows可能还是要自己看看,当前环境或者当前目录,exe能否找到相关插件目录,感觉跟xmake编译关系不大

@jiagushuai
Copy link
Author

jiagushuai commented Feb 22, 2019

  • 有一个问题是我把qt编译的生成的放到虚拟机的裸机也可以执行,感觉跟运行环境没关系

  • 之前用xmake编译的可以在其他电脑上正常运行而且不会报这个错误,但是现在就报错。

  • Mac跟Windows都是报类似找不到平台插件的错误

  • Windows下qt编译的jom文件我找不到
    image

  • Mac平台qt的编译遇到点问题,我重新编译qt之后再发你Mac相关的
    image

  • Mac下生成的可执行程序的依赖关系如下,看着貌似没有依赖qt

gushuai:~ jl$ otool -L /Users/shandikeji/Desktop/Qt/widgetapp/build/macosx/x86_64/release/qt_demo 
/Users/shandikeji/Desktop/Qt/widgetapp/build/macosx/x86_64/release/qt_demo:
	/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1450.15.0)
	/System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics (compatibility version 64.0.0, current version 1129.5.0)
	/System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 158.0.0)
	/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 22.0.0)
	/System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration (compatibility version 1.0.0, current version 1.0.0)
	/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
	/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.11)
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.0.0)
	/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1561.20.106)
	/System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 50.0.0)
	/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 822.19.0)
	/System/Library/Frameworks/CoreText.framework/Versions/A/CoreText (compatibility version 1.0.0, current version 1.0.0)
	/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1450.15.0)
	/usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)

@jiagushuai
Copy link
Author

jiagushuai commented Feb 22, 2019

Windows下我查看对比了moc_mainwindow.cpp文件,没有什么不同
image

  • 更换在xmake编译之后结果也一样 运行报错

@waruqi
Copy link
Member

waruqi commented Feb 22, 2019

  • Mac下生成的可执行程序的依赖关系如下,看着貌似没有依赖qt

因为你现在用的是static qt sdk,静态链接进去了,是看不到的。。

你可以先试下我之前贴的网上的解决方式,看看能否解决问题,不行的话,等用mac 版本 qt编译给下详细 编译链接参数给我。。

或者吧你这的mac qt sdk 打包发我下,我试试

@jiagushuai
Copy link
Author

mac下用qt编译

11:23:03: 为项目static执行步骤 ...
11:23:03: 正在启动 "/Users/shandikeji/Qt/5.7.1/5.7.1/clang_64/bin/qmake" /Users/shandikeji/Desktop/Qt/static/static.pro -r -spec macx-clang CONFIG+=release CONFIG+=x86_64

Info: creating stash file /Users/shandikeji/Desktop/Qt/build-static-qt5_7_1-Release/.qmake.stash
11:23:23: 进程"/Users/shandikeji/Qt/5.7.1/5.7.1/clang_64/bin/qmake"正常退出。
11:23:23: 正在启动 "/usr/bin/make" 

/Users/shandikeji/Qt/5.7.1/5.7.1/clang_64/bin/uic ../static/mainwindow.ui -o ui_mainwindow.h
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -mmacosx-version-min=10.8 -O2 -std=gnu++11 -Wall -W -fPIC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../static -I. -I../../../Qt/5.7.1/5.7.1/clang_64/include -I../../../Qt/5.7.1/5.7.1/clang_64/include/QtWidgets -I../../../Qt/5.7.1/5.7.1/clang_64/include/QtGui -I../../../Qt/5.7.1/5.7.1/clang_64/include/QtCore -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/AGL.framework/Headers -I. -I../../../Qt/5.7.1/5.7.1/clang_64/mkspecs/macx-clang -o main.o ../static/main.cpp
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -mmacosx-version-min=10.8 -O2 -std=gnu++11 -Wall -W -fPIC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../static -I. -I../../../Qt/5.7.1/5.7.1/clang_64/include -I../../../Qt/5.7.1/5.7.1/clang_64/include/QtWidgets -I../../../Qt/5.7.1/5.7.1/clang_64/include/QtGui -I../../../Qt/5.7.1/5.7.1/clang_64/include/QtCore -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/AGL.framework/Headers -I. -I../../../Qt/5.7.1/5.7.1/clang_64/mkspecs/macx-clang -o mainwindow.o ../static/mainwindow.cpp
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -mmacosx-version-min=10.8 -O2 -std=gnu++11 -Wall -W -fPIC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../static -I. -I../../../Qt/5.7.1/5.7.1/clang_64/include -I../../../Qt/5.7.1/5.7.1/clang_64/include/QtWidgets -I../../../Qt/5.7.1/5.7.1/clang_64/include/QtGui -I../../../Qt/5.7.1/5.7.1/clang_64/include/QtCore -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/AGL.framework/Headers -I. -I../../../Qt/5.7.1/5.7.1/clang_64/mkspecs/macx-clang -o static_plugin_import.o /Users/shandikeji/Desktop/Qt/build-static-qt5_7_1-Release/static_plugin_import.cpp
/Users/shandikeji/Qt/5.7.1/5.7.1/clang_64/bin/moc -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -D__APPLE__ -D__GNUC__=4 -D__APPLE_CC__ -I/Users/shandikeji/Qt/5.7.1/5.7.1/clang_64/mkspecs/macx-clang -I/Users/shandikeji/Desktop/Qt/static -I/Users/shandikeji/Qt/5.7.1/5.7.1/clang_64/include -I/Users/shandikeji/Qt/5.7.1/5.7.1/clang_64/include/QtWidgets -I/Users/shandikeji/Qt/5.7.1/5.7.1/clang_64/include/QtGui -I/Users/shandikeji/Qt/5.7.1/5.7.1/clang_64/include/QtCore -I. -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1 -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/include -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include ../static/mainwindow.h -o moc_mainwindow.cpp
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -mmacosx-version-min=10.8 -O2 -std=gnu++11 -Wall -W -fPIC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../static -I. -I../../../Qt/5.7.1/5.7.1/clang_64/include -I../../../Qt/5.7.1/5.7.1/clang_64/include/QtWidgets -I../../../Qt/5.7.1/5.7.1/clang_64/include/QtGui -I../../../Qt/5.7.1/5.7.1/clang_64/include/QtCore -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/AGL.framework/Headers -I. -I../../../Qt/5.7.1/5.7.1/clang_64/mkspecs/macx-clang -o moc_mainwindow.o moc_mainwindow.cpp
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -headerpad_max_install_names -stdlib=libc++ -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -mmacosx-version-min=10.8 -o static.app/Contents/MacOS/static main.o mainwindow.o static_plugin_import.o moc_mainwindow.o   -L/Users/shandikeji/Qt/5.7.1/5.7.1/clang_64/lib -framework DiskArbitration -framework IOKit -framework Foundation -framework CoreServices -framework AppKit -framework ApplicationServices -framework CoreFoundation -framework OpenGL -framework AGL -framework Carbon -L/Users/shandikeji/Qt/5.7.1/5.7.1/clang_64/plugins/platforms -lqcocoa -lcups -lQt5PrintSupport -lQt5Widgets -L/Users/shandikeji/Qt/5.7.1/5.7.1/clang_64/plugins/imageformats -lqdds -lqicns -lqico -lqmacjp2 -framework ImageIO -lQt5PlatformSupport -lqtfreetype -lqtga -lqtiff -lqwbmp -lqwebp -lQt5Gui -lqtpng -lqtharfbuzzng -lQt5Core -lz -lqtpcre -lm 
11:23:38: 进程"/usr/bin/make"正常退出。
11:23:38: Elapsed time: 00:35.
  • 执行结果正常
    image

@waruqi
Copy link
Member

waruqi commented Feb 22, 2019

-o static.app/Contents/MacOS/static

我看了下,你这qt mac生成的是 static.app,能否把这整个app发我下。我觉得这个可能还是部署问题。。

qt生成的是xxx.app,我得确认下,qt是否吧 qt plugins 等依赖的库,都给部署copy到xxx.app进去了,所以直接运行xxx.app就成功了

https://stackoverflow.com/questions/47624198/deploying-a-qt-application-on-mac-this-application-failed-to-start-because-it-c

这个里面有说明。

还有你只都是直接手动运行的 binary程序,还是点击运行的qt 生成的xxx.app程序?

@jiagushuai
Copy link
Author

  • Mac下的话 qt编译生成的是xxx.app程序,直接双击运行或者run都可以
    Mac上通过qt生成binary程序没试过。

@waruqi
Copy link
Member

waruqi commented Feb 22, 2019

qmake会去自动生成一个类似 xxxx_plugin_import.cpp的文件,里面类似:

#include <QtPlugin>
Q_IMPORT_PLUGIN(QXcbIntegrationPlugin)
Q_IMPORT_PLUGIN(QXcbEglIntegrationPlugin)
Q_IMPORT_PLUGIN(QXcbGlxIntegrationPlugin)
Q_IMPORT_PLUGIN(QGifPlugin)
Q_IMPORT_PLUGIN(QICNSPlugin)
Q_IMPORT_PLUGIN(QICOPlugin)
Q_IMPORT_PLUGIN(QJpegPlugin)
Q_IMPORT_PLUGIN(QTgaPlugin)
Q_IMPORT_PLUGIN(QTiffPlugin)
Q_IMPORT_PLUGIN(QWbmpPlugin)
Q_IMPORT_PLUGIN(QWebpPlugin)
Q_IMPORT_PLUGIN(QEglFSKmsEglDeviceIntegrationPlugin)
Q_IMPORT_PLUGIN(QEglFSX11IntegrationPlugin)

然后编译的时候,指定link上对应的plugins,来实现静态链接plugins

你这的编译信息里面,有了这个

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -mmacosx-version-min=10.8 -O2 -std=gnu++11 -Wall -W -fPIC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../static -I. -I../../../Qt/5.7.1/5.7.1/clang_64/include -I../../../Qt/5.7.1/5.7.1/clang_64/include/QtWidgets -I../../../Qt/5.7.1/5.7.1/clang_64/include/QtGui -I../../../Qt/5.7.1/5.7.1/clang_64/include/QtCore -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/AGL.framework/Headers -I. -I../../../Qt/5.7.1/5.7.1/clang_64/mkspecs/macx-clang -o static_plugin_import.o /Users/shandikeji/Desktop/Qt/build-static-qt5_7_1-Release/static_plugin_import.cpp

static_plugin_import.cpp 可以给我看下,我再分析看看

@waruqi
Copy link
Member

waruqi commented Feb 22, 2019

或者你这的qt demo工程可以发我看下

@waruqi
Copy link
Member

waruqi commented Feb 22, 2019

就是这个原因,我手动加了个 plugin_import.cpp

#include <QtPlugin>
Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin)

然后links上对应的plugins库 libqcocoa.a 以及它的一些依赖库,就可以运行起来了。。

我现在需要确认下,这个文件,是qt工程会自动创建出来一直在工程里面维护的,还是只是qmake临时创建编译的。。

所以请提供一下你这qt的demo工程。我好分析下,如果去更好的处理这个问题。。

虽然原因找到了,但我需要花点时间想想怎么处理的更完善些。。

@waruqi
Copy link
Member

waruqi commented Feb 24, 2019

mac static qt sdk版本,我这已经支持了,不过需要改下xmake.lua去支持静态sdk编译,因为静态版本需要导入一些必须的plugin模块才能加载成功。。

-- add modes: debug and release 
add_rules("mode.debug", "mode.release")

-- includes
includes("qt_add_static_plugins.lua")

-- add target
target("qt_demo")

    -- add rules
    add_rules("qt.application")

    -- add headers
    add_headerfiles("src/*.h")

    -- add files
    add_files("src/*.cpp") 
    add_files("src/mainwindow.ui")

    -- add files with Q_OBJECT meta (only for qt.moc)
    add_files("src/mainwindow.h") 

    -- add frameworks
    add_frameworks("QtWidgets")

    -- add plugin: QXXXIntegrationPlugin
    if is_plat("macosx") then
        qt_add_static_plugins("QCocoaIntegrationPlugin", {linkdirs = "plugins/platforms", links = {"qcocoa", "Qt5PrintSupport", "Qt5PlatformSupport", "cups"}})
    elseif is_plat("windows") then
        qt_add_static_plugins("QWindowsIntegrationPlugin", {linkdirs = "plugins/platforms", links = {"Qt5PrintSupport", "Qt5PlatformSupport", "cups"}})
    end

    -- add plugin: QSvgPlugin (optional)
    qt_add_static_plugins("QSvgPlugin", {linkdirs = "plugins/imageformats", links = {"qsvg", "Qt5Svg"}})

widgetapp/quickapp的静态链接都支持了,你可以参考下example工程:
https://github.com/xmake-io/xmake/blob/dev/tests/projects/qt/widgetapp_static
https://github.com/xmake-io/xmake/tree/dev/tests/projects/qt/quickapp_static

qt_add_static_plugins函数是内置的辅助函数,用来添加导入静态qt插件的,如果你的qt工程用到了其他插件,也可以通过这个接口导入并且链接进来,只在静态sdk的时候需要。。

目前这个只在macos static qt sdk测试过, win 上可以参考这,你自己处理下 插件名和链接库:

        qt_add_static_plugins("QWindowsIntegrationPlugin", {linkdirs = "plugins/platforms", links = {"Qt5PrintSupport", "Qt5PlatformSupport", "cups"}})

我还没测试过,可能会缺一些库,你自己补下吧,或者吧win sdk也打包发我看下。。

linux也是如此,可以自己加一下,或者打包给我看下。。

另外dev版本对静态库做了一些其他改进,一些qt需要的静态依赖库,我都内置link进去了,例如:qtpng 等。。

@jiagushuai
Copy link
Author

jiagushuai commented Feb 25, 2019

  • Mac平台编译运行成功
  • Windows平台编译报错找不到cups.lib
D:\LING\Qt\widget>xmake -r  -v
checking for the Microsoft Visual Studio (x86) version ... 2015
checking for the Qt SDK directory ... D:\QtStatic\5.6.3\VS2015Static
checking for the Qt SDK version ... 5.6.3
configure
{
    arch = x86
    ld = link.exe
    project = .
    ccache = true
    mode = release
    qt_sdkver = 5.6.3
    host = windows
    plat = windows
    cxx = cl.exe
    kind = static
    buildir = build
    vs = 2015
    qt = D:\QtStatic\5.6.3\VS2015Static
}
checking for the ccache ... ok
[  0%]: compiling.qt.ui src\mainwindow.ui
D:\QtStatic\5.6.3\VS2015Static\bin\uic.exe      src\mainwindow.ui -o build\.qt\ui\qt_demo\ui_mainwindow.h
checking for the cl.exe ... ok
checking for the flags (-Ox -fp:fast) ... ok
checking for the flags (-std:c++11) ... no
checking for the flags (-fPIC) ... no
[  0%]: ccache compiling.release src\main.cpp
cl.exe -c -Ox -fp:fast -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtWidgets -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtGui -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtQml -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtNetwork -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtCore -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\mkspecs\\\\win32-msvc -ID:\\\\LING\\\\Qt\\\\widget\\\\build\\\\.qt\\\\ui\\\\qt_demo -DQT_NO_DEBUG -DQT_DEPRECATED_WARNINGS -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -D_WINDOWS -nologo -Fobuild\\.objs\\qt_demo\\windows\\x86\\release\\src\\main.cpp.obj src\\main.cpp
[ 40%]: ccache compiling.release build\.qt\plugin\qt_demo\static_import.cpp
cl.exe -c -Ox -fp:fast -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtWidgets -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtGui -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtQml -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtNetwork -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtCore -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\mkspecs\\\\win32-msvc -ID:\\\\LING\\\\Qt\\\\widget\\\\build\\\\.qt\\\\ui\\\\qt_demo -DQT_NO_DEBUG -DQT_DEPRECATED_WARNINGS -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -D_WINDOWS -nologo -Fobuild\\.objs\\qt_demo\\windows\\x86\\release\\build\\.qt\\plugin\\qt_demo\\static_import.cpp.obj build\\.qt\\plugin\\qt_demo\\static_import.cpp
[ 20%]: ccache compiling.release src\mainwindow.cpp
cl.exe -c -Ox -fp:fast -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtWidgets -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtGui -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtQml -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtNetwork -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtCore -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\mkspecs\\\\win32-msvc -ID:\\\\LING\\\\Qt\\\\widget\\\\build\\\\.qt\\\\ui\\\\qt_demo -DQT_NO_DEBUG -DQT_DEPRECATED_WARNINGS -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -D_WINDOWS -nologo -Fobuild\\.objs\\qt_demo\\windows\\x86\\release\\src\\mainwindow.cpp.obj src\\mainwindow.cpp
[ 60%]: compiling.qt.moc src\mainwindow.h
D:\QtStatic\5.6.3\VS2015Static\bin\moc.exe      -DQT_NO_DEBUG -DQT_DEPRECATED_WARNINGS -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -D_WINDOWS -ID:\\QtStatic\\5.6.3\\VS2015Static\\include\\QtWidgets -ID:\\QtStatic\\5.6.3\\VS2015Static\\include\\QtGui -ID:\\QtStatic\\5.6.3\\VS2015Static\\include\\QtQml -ID:\\QtStatic\\5.6.3\\VS2015Static\\include\\QtNetwork -ID:\\QtStatic\\5.6.3\\VS2015Static\\include\\QtCore -ID:\\QtStatic\\5.6.3\\VS2015Static\\include -ID:\\QtStatic\\5.6.3\\VS2015Static\\mkspecs\\win32-msvc -ID:\\LING\\Qt\\widget\\build\\.qt\\ui\\qt_demo src\mainwindow.h -o build\.qt\moc\qt_demo\moc_mainwindow.cpp
cl.exe -c -Ox -fp:fast -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtWidgets -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtGui -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtQml -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtNetwork -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtCore -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\mkspecs\\\\win32-msvc -ID:\\\\LING\\\\Qt\\\\widget\\\\build\\\\.qt\\\\ui\\\\qt_demo -DQT_NO_DEBUG -DQT_DEPRECATED_WARNINGS -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -D_WINDOWS -nologo -Fobuild\\.objs\\qt_demo\\windows\\x86\\release\\build\\.qt\\moc\\qt_demo\\moc_mainwindow.cpp.obj build\\.qt\\moc\\qt_demo\\moc_mainwindow.cpp
[100%]: linking.release qt_demo.exe
link.exe @C:\\Users\\Administrator\\AppData\\Local\\Temp\\.xmake\\190225\\_D8872EA9E8E9A15748953F0BB0721616.args.txt
error: LINK : fatal error LNK1181: 无法打开输入文件“cups.lib”
  • 搜索全局找不到cups.lib
    image
  • qt_add_static_plugins("QWindowsIntegrationPlugin", {linkdirs = "plugins/platforms", links = {"Qt5PrintSupport", "Qt5PlatformSupport", "cups"}})去掉'cpus'后编译报错114个无法解析的外部命令,将
D:\LING\Qt\widget>xmake -r  -v
checking for the Microsoft Visual Studio (x86) version ... 2015
checking for the Qt SDK directory ... D:\QtStatic\5.6.3\VS2015Static
checking for the Qt SDK version ... 5.6.3
configure
{
    arch = x86
    ccache = true
    cxx = cl.exe
    ld = link.exe
    mode = release
    qt_sdkver = 5.6.3
    host = windows
    plat = windows
    project = .
    kind = static
    buildir = build
    vs = 2015
    qt = D:\QtStatic\5.6.3\VS2015Static
}
checking for the ccache ... ok
[  0%]: compiling.qt.ui src\mainwindow.ui
D:\QtStatic\5.6.3\VS2015Static\bin\uic.exe      src\mainwindow.ui -o build\.qt\ui\qt_demo\ui_mainwindow.h
checking for the cl.exe ... ok
checking for the flags (-Ox -fp:fast) ... ok
checking for the flags (-std:c++11) ... no
checking for the flags (-fPIC) ... no
[  0%]: ccache compiling.release src\main.cpp
cl.exe -c -Ox -fp:fast -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtWidgets -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtGui -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtQml -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtNetwork -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtCore -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\mkspecs\\\\win32-msvc -ID:\\\\LING\\\\Qt\\\\widget\\\\build\\\\.qt\\\\ui\\\\qt_demo -DQT_NO_DEBUG -DQT_DEPRECATED_WARNINGS -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -D_WINDOWS -nologo -Fobuild\\.objs\\qt_demo\\windows\\x86\\release\\src\\main.cpp.obj src\\main.cpp
[ 40%]: ccache compiling.release build\.qt\plugin\qt_demo\static_import.cpp
cl.exe -c -Ox -fp:fast -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtWidgets -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtGui -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtQml -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtNetwork -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtCore -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\mkspecs\\\\win32-msvc -ID:\\\\LING\\\\Qt\\\\widget\\\\build\\\\.qt\\\\ui\\\\qt_demo -DQT_NO_DEBUG -DQT_DEPRECATED_WARNINGS -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -D_WINDOWS -nologo -Fobuild\\.objs\\qt_demo\\windows\\x86\\release\\build\\.qt\\plugin\\qt_demo\\static_import.cpp.obj build\\.qt\\plugin\\qt_demo\\static_import.cpp
[ 20%]: ccache compiling.release src\mainwindow.cpp
cl.exe -c -Ox -fp:fast -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtWidgets -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtGui -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtQml -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtNetwork -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtCore -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\mkspecs\\\\win32-msvc -ID:\\\\LING\\\\Qt\\\\widget\\\\build\\\\.qt\\\\ui\\\\qt_demo -DQT_NO_DEBUG -DQT_DEPRECATED_WARNINGS -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -D_WINDOWS -nologo -Fobuild\\.objs\\qt_demo\\windows\\x86\\release\\src\\mainwindow.cpp.obj src\\mainwindow.cpp
[ 60%]: compiling.qt.moc src\mainwindow.h
D:\QtStatic\5.6.3\VS2015Static\bin\moc.exe      -DQT_NO_DEBUG -DQT_DEPRECATED_WARNINGS -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -D_WINDOWS -ID:\\QtStatic\\5.6.3\\VS2015Static\\include\\QtWidgets -ID:\\QtStatic\\5.6.3\\VS2015Static\\include\\QtGui -ID:\\QtStatic\\5.6.3\\VS2015Static\\include\\QtQml -ID:\\QtStatic\\5.6.3\\VS2015Static\\include\\QtNetwork -ID:\\QtStatic\\5.6.3\\VS2015Static\\include\\QtCore -ID:\\QtStatic\\5.6.3\\VS2015Static\\include -ID:\\QtStatic\\5.6.3\\VS2015Static\\mkspecs\\win32-msvc -ID:\\LING\\Qt\\widget\\build\\.qt\\ui\\qt_demo src\mainwindow.h -o build\.qt\moc\qt_demo\moc_mainwindow.cpp
cl.exe -c -Ox -fp:fast -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtWidgets -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtGui -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtQml -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtNetwork -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include\\\\QtCore -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\include -ID:\\\\QtStatic\\\\5.6.3\\\\VS2015Static\\\\mkspecs\\\\win32-msvc -ID:\\\\LING\\\\Qt\\\\widget\\\\build\\\\.qt\\\\ui\\\\qt_demo -DQT_NO_DEBUG -DQT_DEPRECATED_WARNINGS -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_QML_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -D_WINDOWS -nologo -Fobuild\\.objs\\qt_demo\\windows\\x86\\release\\build\\.qt\\moc\\qt_demo\\moc_mainwindow.cpp.obj build\\.qt\\moc\\qt_demo\\moc_mainwindow.cpp
[100%]: linking.release qt_demo.exe
link.exe @C:\\Users\\Administrator\\AppData\\Local\\Temp\\.xmake\\190225\\_D7C126E9A4CE3377ABE7966B99877FA6.args.txt
error: static_import.cpp.obj : error LNK2019: 无法解析的外部符号 "struct QStaticPlugin const __cdecl qt_static_plugin_QWindowsIntegrationPlugin(void)" (?qt_static_plugin_QWindowsIntegrationPlugin@@YA?BUQStaticPlugin@@XZ),该符号在函数 "public: __thiscall StaticQWindowsIntegrationPluginPluginInstance::StaticQWindowsIntegrationPluginPluginInstance(void)" (??0StaticQWindowsIntegrationPluginPluginInstance@@QAE@XZ) 中被引用
Qt5Widgets.lib(qapplication.obj) : error LNK2019: 无法解析的外部符号 __imp__GetDC@4,该符号在函数 "struct HDC__ * __cdecl qt_win_display_dc(void)" (?qt_win_display_dc@@YAPAUHDC__@@XZ) 中被引用

@jiagushuai
Copy link
Author

jiagushuai commented Feb 26, 2019

windows平台上xmake.lua修改后编译运行成功

D:\LING\Qt\widget>xmake -r
checking for the Microsoft Visual Studio (x86) version ... 2015
checking for the Qt SDK directory ... D:\QtStatic\5.6.3\VS2015Static
checking for the Qt SDK version ... 5.6.3
[  0%]: compiling.qt.ui src\mainwindow.ui
[  0%]: ccache compiling.release src\main.cpp
[ 40%]: ccache compiling.release build\.qt\plugin\qt_demo\static_import.cpp
[ 20%]: ccache compiling.release src\mainwindow.cpp
[ 60%]: compiling.qt.moc src\mainwindow.h
[100%]: linking.release qt_demo.exe
build ok!
  • 1.cups修改为qwindows
qt_add_static_plugins("QWindowsIntegrationPlugin", {linkdirs = "plugins/platforms", links = {"Qt5PrintSupport", "Qt5PlatformSupport","cups"}})
#修改为
qt_add_static_plugins("QWindowsIntegrationPlugin", {linkdirs = "plugins/platforms", links = {"Qt5PrintSupport", "Qt5PlatformSupport","qwindows"}})
  • 2.添加链接库
    add_links("ws2_32")
    add_links("GDI32")
    add_links("ole32")
    add_links("ADVAPI32")
    add_links("SHELL32")
    add_links("USER32")
    add_links("qtpcre")
    add_links("OpenGL32")
    add_links("qtharfbuzzng")
    add_links("IMM32")
    add_links("WINMM")

@waruqi
Copy link
Member

waruqi commented Mar 3, 2019

windows的这些qt sys links 我内置进去了。。user32这些

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants