M1 Mac下用vcpkg安装hello-imgui后CMake无法找到该包
解决M1 Mac上vcpkg安装hello-imgui后CMake找不到配置文件的问题
可能的原因及解决方案
1. 确保CMake正确加载vcpkg工具链文件
你之前能成功编译fmt,大概率是因为当时正确指定了vcpkg工具链,但本次构建未配置。M1 Mac的arm64架构下,必须让CMake通过vcpkg工具链查找包:
执行CMake配置时添加工具链参数:
cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=/path/to/your/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=arm64-osx
替换/path/to/your/vcpkg为实际的vcpkg安装路径,arm64-osx是M1 Mac对应的triplet(若vcpkg默认triplet已设为该值,可省略-DVCPKG_TARGET_TRIPLET)。
2. 检查hello-imgui配置文件是否存在
先确认vcpkg是否安装了完整的配置文件:
ls /path/to/your/vcpkg/installed/arm64-osx/share/hello-imgui/
若输出中没有hello-imguiConfig.cmake或hello-imgui-config.cmake,说明安装不完整,重新执行安装:
vcpkg remove hello-imgui --clean-after-build vcpkg install hello-imgui --triplet arm64-osx
3. 手动指定hello-imgui配置路径
如果工具链方式失效,可直接在CMake命令行强制指定配置文件路径:
cmake -S . -B build -Dhello-imgui_DIR=/path/to/your/vcpkg/installed/arm64-osx/share/hello-imgui/
也可以在CMakeLists.txt的find_package之前添加:
set(hello-imgui_DIR "/path/to/your/vcpkg/installed/arm64-osx/share/hello-imgui/")
4. 确认CMake版本兼容性
hello-imgui可能对CMake版本有要求,你当前指定了3.24,先确认本地CMake版本达标:
cmake --version
若版本低于3.24,可通过homebrew升级:
brew upgrade cmake
内容的提问来源于stack exchange,提问作者Mahdi Habibi
相关产品推荐
相关产品推荐

