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

Fix syslinks error using qt static lib in mingw #5202

Merged
merged 3 commits into from
Jun 7, 2024
Merged

Conversation

F11st
Copy link

@F11st F11st commented Jun 6, 2024

问题出现在使用msys/mingw环境下,使用在使用qt5静态库编译时,xmake在_add_qmakeprllibs函数中读取
qt lib文件夹下对应库prl文件中QMAKE_PRL_LIBS_FOR_CMAKE值作为syslink添加。
以Qt5Core.prl为例

...
QMAKE_PRL_LIBS_FOR_CMAKE = -lmpr;-luserenv;-lversion;-lz;$$[QT_INSTALL_LIBS]/libqtpcre2.a;-lzstd;-lnetapi32;-lws2_32;-ladvapi32;-lkernel32;-lole32;-lshell32;-luuid;-luser32;-lwinmm;;

最终添加的syslinks为 target:add("syslinks", "-lmpr")-l重复添加,造成编译时链接失败,链接错误日志如下

x86_64-w64-mingw32-g++ -o build\mingw\x86_64\release\qt.exe build\.objs\qt\mingw\x86_64\release\src\main.cpp.obj build\.objs\qt\mingw\x86_64\release\src\mainwindow.cpp.obj build\.objs\qt\mingw\x86_64\release\gens\src\moc_mainwindow.cpp.obj -m64 -LD:\ProgramFilesScoop\apps\msys2\2024-05-07\mingw64\qt5-static\lib -s D:/ProgramFilesScoop/apps/msys2/2024-05-07/mingw64/qt5-static/lib/libQt5Gui.a -l-ld3d11 -l-ldxgi -l-ldxguid D:/ProgramFilesScoop/apps/msys2/2024-05-07/mingw64/qt5-static/lib/libqtlibpng.a D:/ProgramFilesScoop/apps/msys2/2024-05-07/mingw64/qt5-static/lib/libqtharfbuzz.a D:/ProgramFilesScoop/apps/msys2/2024-05-07/mingw64/qt5-static/lib/libQt5Core.a -l-luxtheme -l-ldwmapi -l-lcomdlg32 -l-loleaut32 -l-limm32 -l-lglu32 -l-lopengl32 -l-lgdi32 -l-lmpr -l-luserenv -l-lversion -l-lz D:/ProgramFilesScoop/apps/msys2/2024-05-07/mingw64/qt5-static/lib/libqtpcre2.a -l-lzstd -l-lnetapi32 -l-lws2_32 -l-ladvapi32 -l-lkernel32 -l-lole32 -l-lshell32 -l-luuid -l-luser32 -l-lwinmm -lqtfreetype -lqtharfbuzz -lqtlibjpeg -lqtlibpng -lqtmain -lqtopenwnn -lqtpcre2 -lqtpinyin -lqttcime -lqt_clip2tri -lqt_clipper -lqt_poly2tri -lmingw32 -lws2_32 -lgdi32 -lole32 -ladvapi32 -lshell32 -luser32 -liphlpapi -mwindows

第二处是链接时,链接顺序问题,应当先链接a文件,后链接对应prl文件中的依赖库

@@ -158,6 +158,9 @@ function _add_qmakeprllibs(target, prlfile, qtlibdir)
target:add("linkdirs", libdir)
else
local libstr = string.gsub(lib, "%$%$%[QT_INSTALL_LIBS%]", qtlibdir)
if libstr:startswith("-l") then
libstr = lib:sub(3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不是应该 libstr:sub 么?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不好意思,这里我漏看了,但是效果一样。新的提交应该是改了,但是刚才我误操作了force push不知道会不会影响

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

只要最终 patch 没问题就行

@waruqi waruqi merged commit e3e40cf into xmake-io:dev Jun 7, 2024
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants