CLion配置Qt WebAssembly项目CMake失败的问题及解决方法
问题:CLion中配置Qt for WebAssembly CMake失败,找不到Qt6BundledZLIB
问题背景
我用Qt for WebAssembly开发的小型应用在控制台和Qt Creator中构建运行正常,但切换到CLion作为主IDE时,CMake配置始终失败。相同项目在旧Ubuntu机器上运行无此问题。
已执行的配置操作
1. 工具链环境配置
在工具链中引入环境文件,设置C/C++编译器,环境变量如下:
export EMSDK=/home/emmynoether/emsdk export EM_CONFIG=/home/emmynoether/emsdk/.emscripten export QMAKESPEC=wasm-emscripten export QT_WEBASSEMBLY_ROOT_PATH=/home/emmynoether/Qt/6.8.3/wasm_singlethread export PATH="/home/emmynoether/emsdk/upstream/emscripten:/home/emmynoether/emsdk/node/22.16.0_64bit/bin:$PATH"
2. CMake选项设置
指定Host和Target Qt的CMake参数:
-DQt6_DIR=/home/emmynoether/Qt/6.8.3/wasm_singlethread/lib/cmake/Qt6 -DQT_HOST_PATH=/home/emmynoether/Qt/6.8.3/gcc_64
错误信息
执行CMake配置后出现以下错误:
/home/emmynoether/Downloads/clion-2025.1.3/bin/cmake/linux/x64/bin/cmake -DCMAKE_MAKE_PROGRAM=ninja -DCMAKE_C_COMPILER=/home/emmynoether/emsdk/upstream/emscripten/emcc -DCMAKE_CXX_COMPILER=/home/emmynoether/emsdk/upstream/emscripten/em++ -DQt6_DIR=/home/emmynoether/Qt/6.8.3/wasm_singlethread/lib/cmake/Qt6 -DQT_HOST_PATH=/home/emmynoether/Qt/6.8.3/gcc_64 -G Ninja -S /home/emmynoether/Dokumente/Webseite/MaterialStack -B /home/emmynoether/Dokumente/Webseite/MaterialStack/cmake-build-default-qt-webassembly -- The CXX compiler identification is Clang 19.0.0 -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - failed -- Check for working CXX compiler: /home/emmynoether/emsdk/upstream/emscripten/em++ -- Check for working CXX compiler: /home/emmynoether/emsdk/upstream/emscripten/em++ - works -- Detecting CXX compile features -- Detecting CXX compile features - done -- CMAKE_CXX_COMPILER = /home/emmynoether/emsdk/upstream/emscripten/em++ -- ENV EMSDK = /home/emmynoether/emsdk -- ENV EM_CONFIG = /home/emmynoether/emsdk/.emscripten -- PATH = /home/emmynoether/emsdk/upstream/emscripten:/home/emmynoether/emsdk/node/22.16.0_64bit/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/emmynoether/.dotnet/tools:/home/emmynoether/Downloads/clion-2025.1.3/bin/ninja/linux/x64 -- Qt6_DIR = /home/emmynoether/Qt/6.8.3/wasm_singlethread/lib/cmake/Qt6 -- HOME = /home/emmynoether CMake Warning at /home/emmynoether/Qt/6.8.3/wasm_singlethread/lib/cmake/Qt6/QtFindWrapHelper.cmake:69 (find_package): By not providing "FindQt6BundledZLIB.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "Qt6BundledZLIB", but CMake did not find one. Could not find a package configuration file provided by "Qt6BundledZLIB" with any of the following names: Qt6BundledZLIBConfig.cmake qt6bundledzlib-config.cmake Add the installation prefix of "Qt6BundledZLIB" to CMAKE_PREFIX_PATH or set "Qt6BundledZLIB_DIR" to a directory containing one of the above files. If "Qt6BundledZLIB" provides a separate development package or SDK, be sure it has been installed. Call Stack (most recent call first): /home/emmynoether/Qt/6.8.3/wasm_singlethread/lib/cmake/Qt6/FindWrapZLIB.cmake:6 (qt_find_package_system_or_bundled) /home/emmynoether/Downloads/clion-2025.1.3/bin/cmake/linux/x64/share/cmake-3.31/Modules/CMakeFindDependencyMacro.cmake:76 (find_package) /home/emmynoether/Qt/6.8.3/wasm_singlethread/lib/cmake/Qt6/QtPublicDependencyHelpers.cmake:36 (find_dependency) /home/emmynoether/Qt/6.8.3/wasm_singlethread/lib/cmake/Qt6Core/Qt6CoreDependencies.cmake:38 (_qt_internal_find_third_party_dependencies) /home/emmynoether/Qt/6.8.3/wasm_singlethread/lib/cmake/Qt6Core/Qt6CoreConfig.cmake:45 (include) /home/emmynoether/Qt/6.8.3/wasm_singlethread/lib/cmake/Qt6/Qt6Config.cmake:196 (find_package) CMakeLists.txt:16 (find_package)
解决方案
问题根源在于预编译的Qt for WebAssembly包未包含bundled ZLIB的CMake配置文件,需从源码编译Qt并添加-qt-zlib参数:
# 激活Emscripten环境 source /home/emmynoether/emsdk/emsdk_env.sh # 创建编译目录并进入 mkdir -p $HOME/qt-build && cd $HOME/qt-build # 设置Host Qt路径 export QT_HOST_PATH=$HOME/Qt/6.8.3/gcc_64 # 克隆Qt 6.8.3源码 git clone --depth 1 --branch v6.8.3 https://code.qt.io/qt/qt5.git qt6-src cd qt6-src # 拉取所有子模块 git submodule sync git submodule update --init --recursive # 配置Qt编译参数 ./configure \ -xplatform wasm-emscripten \ -prefix $HOME/Qt/6.8.3/wasm_singlethread \ -opensource -confirm-license \ -nomake tests -nomake examples \ -skip qtwebengine \ -qt-zlib \ -release \ -opengl es2 # 编译并安装Qt cmake --build . --parallel $(nproc) cmake --install .
编译安装完成后,CLion中的CMake配置即可正常运行。
内容的提问来源于stack exchange,提问作者Suslik
相关产品推荐
相关产品推荐

