You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CMake构建项目时找不到Qt5Core.lib的问题咨询

问题

执行cmake .构建项目时,find_package(Qt5Core REQUIRED)命令失败,报错如下:

CMake Error at C:/Qt/Tools/QtDesignStudio/qt5_design_studio_reduced_version/lib/cmake/Qt5Core/Qt5CoreConfig.cmake:14 (message):
  The imported target "Qt5::Core" references the file

     "C:/Qt/Tools/QtDesignStudio/qt5_design_studio_reduced_version/lib/Qt5Core.lib"

  but this file does not exist.  Possible reasons include:

  * The file was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and contained

     "C:/Qt/Tools/QtDesignStudio/qt5_design_studio_reduced_version/lib/cmake/Qt5Core/Qt5CoreConfig.cmake"

  but not all the files it references.

在对应目录下仅能找到Qt5Core.prl和Qt5Core.dll,无法找到Qt5Core.lib,需明确该文件不存在的原因及获取方法。

相关Qt5CoreConfig.cmake代码片段:

if(NOT EXISTS "${file}" )
        message(FATAL_ERROR "The imported target \"Qt5::Core\" references the file
   \"${file}\"
but this file does not exist.  Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
   \"${CMAKE_CURRENT_LIST_FILE}\"
but not all the files it references.
")
    endif()

原因分析

  • 你使用的是Qt Design Studio附带的精简版Qt,这个版本仅提供运行时依赖文件(如Qt5Core.dll),仅用于支持设计预览功能,不包含编译项目所需的静态导入库(.lib文件)。
  • 精简版的CMake配置文件存在错误,错误引用了不存在的Qt5Core.lib,属于安装包的配置缺陷。

解决方法

  • 安装完整Qt开发环境:卸载当前的Qt Design Studio精简版Qt,通过Qt官方安装器安装完整的Qt开发包,安装时选择对应编译器的Qt版本(如MSVC、MinGW),安装完成后会自动包含所有编译所需的.lib文件。
  • 指定正确的Qt路径:修改项目的CMakeLists.txt,设置CMAKE_PREFIX_PATH指向完整Qt的安装目录,或者直接指定Qt5的配置路径,示例:
    set(Qt5_DIR "C:/Qt/5.15.2/msvc2019_64/lib/cmake/Qt5")
    find_package(Qt5Core REQUIRED)
    
  • 不推荐手动复制.lib文件:从其他完整Qt安装目录复制同版本的Qt5Core.lib到当前路径可能暂时解决问题,但容易因版本、编译器不匹配引发后续编译或运行错误。

内容的提问来源于stack exchange,提问作者polarfuchs

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 10:10:49