使用vcpkg安装glad失败:CMake版本兼容性问题求助
问题描述
执行命令 .\vcpkg.exe install glad:x64-windows 通过vcpkg安装glad时,触发如下CMake错误:
CMake Error at CMakeLists.txt:1 (cmake_minimum_required): Compatibility with CMake < 3.5 has been removed from CMake. Update the VERSION argument <min> value. Or, use the <min>...<max> syntax to tell CMake that the project requires at least <min> but has been updated to work with policies introduced by <max> or earlier. Or, add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to try configuring anyway. -- Configuring incomplete, errors occurred!
当前使用CMake版本为4.0.0,已尝试在vcpkg目录执行bootstrap-vcpkg.bat和git pull操作,问题仍未解决。
解决方案
方案1:修改glad端口的CMakeLists.txt
- 找到vcpkg中glad端口的目录,通常路径为
vcpkg\ports\glad - 打开该目录下的
CMakeLists.txt,修改第一行的cmake_minimum_required指令:- 直接将版本提升至3.5:
cmake_minimum_required(VERSION 3.5) - 或使用区间语法明确兼容范围:
cmake_minimum_required(VERSION 3.5...4.0)
- 直接将版本提升至3.5:
- 重新执行安装命令:
.\vcpkg.exe install glad:x64-windows
方案2:通过vcpkg传递CMake参数
安装时直接指定策略参数绕过版本检查:
.\vcpkg.exe install glad:x64-windows --cmake-args="-DCMAKE_POLICY_VERSION_MINIMUM=3.5"
方案3:临时降级CMake版本
如果上述方案无效,可临时将CMake降级到3.x系列版本(如3.27.x),待glad安装完成后再升级回4.0.0。CMake官网提供各版本安装包,安装后确保环境变量中CMake路径指向降级后的版本。
内容的提问来源于stack exchange,提问作者Stephan Dolskii
相关产品推荐
相关产品推荐

