-
-
Notifications
You must be signed in to change notification settings - Fork 814
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
Archlinux上set_config设置的qt_sdkver只在初次运行xmake时生效 #4881
Comments
Title: set_config only takes effect when xmake is run for the first time. |
这边测试没啥问题,没法复现你的问题。。另外,版本应该是 add_rules("mode.debug", "mode.release")
set_config("qt_sdkver", "6.6.0")
set_languages("c++20")
target("demo")
add_rules("qt.widgetapp")
add_headerfiles("src/*.h")
add_files("src/*.cpp")
add_files("src/mainwindow.ui")
add_files("src/mainwindow.h") PS D:\projects\personal\xmake\tests\projects\qt\widgetapp> xmake f --qt=D:\projects\personal\Qt -c
checking for platform ... windows
checking for architecture ... x64
checking for Microsoft Visual Studio (x64) version ... 2022
checking for Qt SDK directory ... D:/projects/personal/Qt/6.6.0/msvc2019_64
checking for Qt SDK version ... 6.6.0
PS D:\projects\personal\xmake\tests\projects\qt\widgetapp> xmake -r
[ 28%]: compiling.qt.ui src\mainwindow.ui
[ 42%]: compiling.qt.moc src\mainwindow.h
[ 57%]: compiling.release src\main.cpp
[ 71%]: compiling.release src\mainwindow.cpp
[ 85%]: linking.release demo.exe
[100%]: build ok, spent 8.015s
PS D:\projects\personal\xmake\tests\projects\qt\widgetapp> xmake
checking for Microsoft Visual Studio (x64) version ... 2022
checking for Qt SDK directory ... D:/projects/personal/Qt/6.6.0/msvc2019_64
checking for Qt SDK version ... 6.6.0
[100%]: build ok, spent 0.609s
PS D:\projects\personal\xmake\tests\projects\qt\widgetapp> xmake
checking for Microsoft Visual Studio (x64) version ... 2022
checking for Qt SDK directory ... D:/projects/personal/Qt/6.6.0/msvc2019_64
checking for Qt SDK version ... 6.6.0
[ 57%]: compiling.release src\main.cpp
[ 71%]: compiling.release src\mainwindow.cpp
[ 85%]: linking.release demo.exe
[100%]: build ok, spent 2.859s
PS D:\projects\personal\xmake\tests\projects\qt\widgetapp> xmake
checking for Microsoft Visual Studio (x64) version ... 2022
checking for Qt SDK directory ... D:/projects/personal/Qt/6.6.0/msvc2019_64
checking for Qt SDK version ... 6.6.0
[ 57%]: compiling.release src\main.cpp
[ 71%]: compiling.release src\mainwindow.cpp
[ 85%]: linking.release demo.exe
[100%]: build ok, spent 4.203s |
There is nothing wrong with the test here, and I cannot reproduce your problem. . In addition, the version should be add_rules("mode.debug", "mode.release")
set_config("qt_sdkver", "6.6.0")
set_languages("c++20")
target("demo")
add_rules("qt.widgetapp")
add_headerfiles("src/*.h")
add_files("src/*.cpp")
add_files("src/mainwindow.ui")
add_files("src/mainwindow.h") PS D:\projects\personal\xmake\tests\projects\qt\widgetapp> xmake f --qt=D:\projects\personal\Qt -c
checking for platform...windows
checking for architecture... x64
checking for Microsoft Visual Studio (x64) version ... 2022
checking for Qt SDK directory ... D:/projects/personal/Qt/6.6.0/msvc2019_64
checking for Qt SDK version ... 6.6.0
PS D:\projects\personal\xmake\tests\projects\qt\widgetapp> xmake -r
[28%]: compiling.qt.ui src\mainwindow.ui
[42%]: compiling.qt.moc src\mainwindow.h
[57%]: compiling.release src\main.cpp
[71%]: compiling.release src\mainwindow.cpp
[85%]: linking.release demo.exe
[100%]: build ok, spent 8.015s
PS D:\projects\personal\xmake\tests\projects\qt\widgetapp> xmake
checking for Microsoft Visual Studio (x64) version ... 2022
checking for Qt SDK directory ... D:/projects/personal/Qt/6.6.0/msvc2019_64
checking for Qt SDK version ... 6.6.0
[100%]: build ok, spent 0.609s
PS D:\projects\personal\xmake\tests\projects\qt\widgetapp> xmake
checking for Microsoft Visual Studio (x64) version ... 2022
checking for Qt SDK directory ... D:/projects/personal/Qt/6.6.0/msvc2019_64
checking for Qt SDK version ... 6.6.0
[57%]: compiling.release src\main.cpp
[71%]: compiling.release src\mainwindow.cpp
[85%]: linking.release demo.exe
[100%]: build ok, spent 2.859s
PS D:\projects\personal\xmake\tests\projects\qt\widgetapp> xmake
checking for Microsoft Visual Studio (x64) version ... 2022
checking for Qt SDK directory ... D:/projects/personal/Qt/6.6.0/msvc2019_64
checking for Qt SDK version ... 6.6.0
[57%]: compiling.release src\main.cpp
[71%]: compiling.release src\mainwindow.cpp
[85%]: linking.release demo.exe
[100%]: build ok, spent 4.203s |
我按你说的把版本设置为6.6.2, 结果还是跟我最初描述的一样。 $ tree -a
.
├── .gitignore
├── src
│ ├── main.cpp
│ ├── mainwindow.cpp
│ ├── mainwindow.h
│ └── mainwindow.ui
└── xmake.lua
2 directories, 6 files $ cat xmake.lua
add_rules("mode.debug", "mode.release")
set_config("qt_sdkver", "6.6.2")
set_languages("c++20")
target("mp")
add_rules("qt.widgetapp")
add_headerfiles("src/*.h")
add_files("src/*.cpp")
add_files("src/mainwindow.ui")
-- add files with Q_OBJECT meta (only for qt.moc)
add_files("src/mainwindow.h")
$ xmake
checking for platform ... linux
checking for architecture ... x86_64
checking for Qt SDK directory ... /usr
checking for Qt SDK version ... 6.6.2
[ 28%]: compiling.qt.ui src/mainwindow.ui
[ 42%]: compiling.qt.moc src/mainwindow.h
[ 57%]: cache compiling.release src/mainwindow.cpp
[ 71%]: cache compiling.release src/main.cpp
[ 85%]: linking.release mp
[100%]: build ok, spent 5.048s
$ touch xmake.lua
$ xmake
checking for Qt SDK directory ... /usr
checking for Qt SDK version ... 5.15.13
[ 57%]: cache compiling.release src/mainwindow.cpp
[ 71%]: cache compiling.release src/main.cpp
[ 85%]: linking.release mp
error: /usr/bin/ld: build/.objs/mp/linux/x86_64/release/gens/src/moc_mainwindow.cpp.o:(.data.rel.ro._ZTV10MainWindow[_ZTV10MainWindow]+0xf0): undefined reference to `QWidget::enterEvent(QEnterEvent*)'
/usr/bin/ld: build/.objs/mp/linux/x86_64/release/gens/src/moc_mainwindow.cpp.o:(.data.rel.ro._ZTV10MainWindow[_ZTV10MainWindow]+0x168): undefined reference to `QWidget::nativeEvent(QByteArray const&, void*, long long*)'
collect2: error: ld returned 1 exit status $ xmake clean
$ xmake
[ 28%]: compiling.qt.ui src/mainwindow.ui
[ 42%]: compiling.qt.moc src/mainwindow.h
[ 57%]: cache compiling.release src/mainwindow.cpp
[ 71%]: cache compiling.release src/main.cpp
[ 85%]: linking.release mp
[100%]: build ok, spent 3.631s $ ldd build/linux/x86_64/release/mp
linux-vdso.so.1 (0x00007ffcfd15e000)
libQt5Gui.so.5 => /usr/lib/libQt5Gui.so.5 (0x0000740b16c00000)
libQt5Widgets.so.5 => /usr/lib/libQt5Widgets.so.5 (0x0000740b16400000)
libQt5Core.so.5 => /usr/lib/libQt5Core.so.5 (0x0000740b15e00000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x0000740b15a00000)
.... 以上是我这里的完整复现操作过程。 我怀疑你复现不了是因为你直接指定了qt目录,这样xmake必定能找到对应版本的qt, 我这边的系统是Archlinux, 系统中同时存在Qt5和Qt6: $ qmake -query
QT_SYSROOT:
QT_INSTALL_PREFIX:/usr
QT_INSTALL_ARCHDATA:/usr/lib/qt
QT_INSTALL_DATA:/usr/share/qt
QT_INSTALL_DOCS:/usr/share/doc/qt
QT_INSTALL_HEADERS:/usr/include/qt
QT_INSTALL_LIBS:/usr/lib
QT_INSTALL_LIBEXECS:/usr/lib/qt/libexec
QT_INSTALL_BINS:/usr/bin
QT_INSTALL_TESTS:/usr/tests
QT_INSTALL_PLUGINS:/usr/lib/qt/plugins
QT_INSTALL_IMPORTS:/usr/lib/qt/imports
QT_INSTALL_QML:/usr/lib/qt/qml
QT_INSTALL_TRANSLATIONS:/usr/share/qt/translations
QT_INSTALL_CONFIGURATION:/etc/xdg
QT_INSTALL_EXAMPLES:/usr/share/doc/qt/examples
QT_INSTALL_DEMOS:/usr/share/doc/qt/examples
QT_HOST_PREFIX:/usr
QT_HOST_DATA:/usr/lib/qt
QT_HOST_BINS:/usr/bin
QT_HOST_LIBS:/usr/lib
QMAKE_SPEC:linux-g++
QMAKE_XSPEC:linux-g++
QMAKE_VERSION:3.1
QT_VERSION:5.15.13
$ qmake6 -query
QT_SYSROOT:
QT_INSTALL_PREFIX:/usr
QT_INSTALL_ARCHDATA:/usr/lib/qt6
QT_INSTALL_DATA:/usr/share/qt6
QT_INSTALL_DOCS:/usr/share/doc/qt6
QT_INSTALL_HEADERS:/usr/include/qt6
QT_INSTALL_LIBS:/usr/lib
QT_INSTALL_LIBEXECS:/usr/lib/qt6
QT_INSTALL_BINS:/usr/lib/qt6/bin
QT_INSTALL_TESTS:/usr/tests
QT_INSTALL_PLUGINS:/usr/lib/qt6/plugins
QT_INSTALL_QML:/usr/lib/qt6/qml
QT_INSTALL_TRANSLATIONS:/usr/share/qt6/translations
QT_INSTALL_CONFIGURATION:
QT_INSTALL_EXAMPLES:/usr/share/doc/qt6/examples
QT_INSTALL_DEMOS:/usr/share/doc/qt6/examples
QT_HOST_PREFIX:/usr
QT_HOST_DATA:/usr/lib/qt6
QT_HOST_BINS:/usr/lib/qt6/bin
QT_HOST_LIBEXECS:/usr/lib/qt6
QT_HOST_LIBS:/usr/lib
QMAKE_SPEC:linux-g++
QMAKE_XSPEC:linux-g++
QMAKE_VERSION:3.1
QT_VERSION:6.6.2 |
尽管这边指定目录,但是指定的是根目录,里面有 5.x 6.x 两个版本,如果不指定版本,也是不确定版本的。
xmake f --qt=qtsdk 指定的也是根目录而已。 这边没有 archlinux + qt 去测试复现 |
可能跟你这安装在 /usr/ 的 qmake 有关,qmake 查找有缓存。试下这个 patch #4910 不过我没环境测试。。 |
Although the directory is specified here, it is the root directory, which contains two versions, 5.x and 6.x. If the version is not specified, the version is not sure. -qtsdk xmake f --qt=qtsdk The specified one is also the root directory. There is no archlinux + qt here to test reproduction |
这个patch我试了, 没有效果. 我看了下代码, 问题出在这里 xmake/xmake/modules/detect/sdks/find_qt.lua Lines 144 to 161 in 0a6b495
当第一次运行时, _find_sdkdir 返回空,因为 sdkdir 为空导致find_file 时paths 为空,此时_find_qmake 会执行到L155,找到带sdkver:major() 后缀的qmake6.
找到qmake后,在main里会有这么一步 xmake/xmake/modules/detect/sdks/find_qt.lua Line 270 in 0a6b495
这里会导致下次运行时, _find_sdkdir 中的sdkdir 为/usr , 这个函数最终会返回/usr/bin/qmake , 导致版本变成qt5, _find_qmake L149直接返回, qt_sdkver 失效.
Arch系统在 解决办法有两种, 一种是之前提过的直接指定qmake路径 #3555, 这种方式比较直接, xmake/xmake/modules/detect/sdks/find_qt.lua Line 270 in 0a6b495
_find_qmake 每次都去执行L155的流程, 因为本来也没主动去设置sdkdir. 第二种方式我测试了是可以的, 但不知道去掉之后的影响有多大.
|
I tried this patch, but it didn't work. I looked at the code and the problem lies here xmake/xmake/modules/detect/sdks/find_qt.lua Lines 144 to 161 in 0a6b495
When running for the first time, _find_sdkdir returns empty. Because sdkdir is empty, paths in find_file is empty. At this time, _find_qmake will execute to L155 and find the suffix with sdkver:major() qmake6.
After finding qmake, there will be such a step in main xmake/xmake/modules/detect/sdks/find_qt.lua Line 270 in 0a6b495
This will cause the sdkdir in _find_sdkdir to be /usr the next time it is run. This function will eventually return /usr/bin/qmake , causing the version to become qt5, _find_qmake L149 will return directly, qt_sdkver is invalid.
The Arch system has both There are two solutions. One is to directly specify the qmake path #3555 mentioned before. This method is more direct. |
sdkdir 没啥问题,你 qmake/qmake6 都在这个路径,原本就要缓存的,根本原因是第二次执行, qt_sdkver 为啥没取到导致找错了。。 |
There is no problem with sdkdir. Your qmake/qmake6 are all in this path, and they were originally cached. The root cause is that the second execution, why qt_sdkver was not retrieved, caused the error to be found. . |
因为_find_sdkdir参数里的sdkver没有作用,在arch上这个函数末尾的find_tool必然会找到/usr下等我bin/qmake |
Because the sdkver in the _find_sdkdir parameter has no effect, the find_tool at the end of this function on arch will definitely find /usr, wait for me bin/qmake |
而且二次运行的时候 qt_sdkver 是正常的值, 以下是我测试时打印的日志: $ env XMAKE_PROGRAM_DIR=/path/to/xmake/xmake xmake
config.get(qt): /usr
global.get(qt):
config.get(sdk):
opt.version:
config.get(qt_sdkver) 6.6.2
_find_qt sdkdir: /usr
_find_qt sdkver: 6.6.2
in _find_sdkdir sdkdir: /usr
in _find_sdkdir sdkver: 6.6.2
_find_sdkdir subdirs: {
"6.6.2/gcc_64/bin",
"6.6.2/clang_64/bin",
"*/bin",
"bin"
}
_find_sdkdir paths: {
"/usr"
}
in _find_file _path: /usr
in _find_file _s_path: /usr
in _find_file filedir: /usr/6.6.2/gcc_64/bin
in _find_file filedir: /usr/6.6.2/clang_64/bin
in _find_file filedir: /usr/*/bin
in _find_file filedir: /usr/bin
sdkdir: /usr
qmakefile: /usr/bin/qmake
_find_qmake: /usr/bin/qmake xmake/xmake/modules/detect/sdks/find_qt.lua Line 137 in 0a6b495
这段代码只能在上面/usr那几个路径下面找qmake, 找到的必然是/usr/bin/qmake, 问题就在这里 |
Moreover, qt_sdkver was a normal value during the second run. The following is the log printed during my test: $ env XMAKE_PROGRAM_DIR=/path/to/xmake/xmake xmake
config.get(qt): /usr
global.get(qt):
config.get(sdk):
opt.version:
config.get(qt_sdkver) 6.6.2
_find_qt sdkdir: /usr
_find_qt sdkver: 6.6.2
in _find_sdkdir sdkdir: /usr
in _find_sdkdir sdkver: 6.6.2
_find_sdkdir subdirs: {
"6.6.2/gcc_64/bin",
"6.6.2/clang_64/bin",
"*/bin",
"bin"
}
_find_sdkdir paths: {
"/usr"
}
in _find_file _path: /usr
in _find_file _s_path: /usr
in _find_file filedir: /usr/6.6.2/gcc_64/bin
in _find_file filedir: /usr/6.6.2/clang_64/bin
in _find_file filedir: /usr/*/bin
in _find_file filedir: /usr/bin
sdkdir: /usr
qmakefile: /usr/bin/qmake
_find_qmake: /usr/bin/qmake xmake/xmake/modules/detect/sdks/find_qt.lua Line 137 in 0a6b495
This code can only find qmake under the /usr paths above. What it finds must be /usr/bin/qmake. The problem lies here. |
改了下,再试试 |
Change it and try again |
现在正常了. Arch系统没问题, 其他系统我也不太熟悉, 就没法帮你测试了. |
It's normal now. There's no problem with Arch system. I'm not familiar with other systems, so I can't help you test it. |
Xmake 版本
v2.8.9+20240321
操作系统版本和架构
Archlinux 6.8.1 x86_64
描述问题
xmake create -l c++ -t qt.widgetapp -P xm; cd xm
set_config("qt_sdkver", "6.6")
, 此时运行xmake
, 会提示checking for Qt SDK version ... 6.6.2
,运行ldd
显示target确实链接到qt6对应的soset_languages("c++20")
, 再次运行xmake
会重新检查qt sdk, 但此时会输出checking for Qt SDK version ... 5.15.13
, 首行的set_config没有生效,且运行结果为链接错误(undefined reference to [some qt libs...]), 此时运行xmake clean; xmake
, 编译成功且target链接到qt5对应的so期待的结果
set_config中设置的qt_sdkver在重新运行时保持生效
工程配置
以下为
xmake create -l c++ -t qt.widgetapp
默认生成, 修改内容已在注释中标记附加信息和错误日志
无
The text was updated successfully, but these errors were encountered: