如何使用cmake和vcpkg在MacOS上导入GLAD/GLFW3/ImGUI库?



我的目标是使用ImGUI编写一个简单的、可移植的应用程序。我还希望使用cmake和vcpkg安装依赖项的平台无关构建体验。我在我的Windows电脑上构建并运行了该程序,但在我的Macbook (macOS Monterey 12.6)上却无法运行。

这是我的vcpkg.json:
{
"name": "imguitest",
"version": "1.0",
"dependencies": [
"glad",
"glfw3",
{
"name": "imgui",
"features": [ "glfw-binding", "opengl3-binding" ]
}
]
}

这是我的CMakeLists.txt:

cmake_minimum_required (VERSION 3.23)
project(ImGui-Test)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
add_executable(${PROJECT_NAME}
src/main.cpp
)
find_package(glad CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE glad::glad)
find_package(glfw3 CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE glfw)
find_package(imgui CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE imgui::imgui)
find_package(OpenGL REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE OpenGL::GL)

运行后:

# export VCPKG_DIR=/path/to/vcpkg/repo/
cmake -B ./build -S . "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake"

我得到这个错误:

CMake Error at CMakeLists.txt:14 (find_package):
Could not find a package configuration file provided by "glad" with any of
the following names:
gladConfig.cmake
glad-config.cmake
Add the installation prefix of "glad" to CMAKE_PREFIX_PATH or set
"glad_DIR" to a directory containing one of the above files.  If "glad"
provides a separate development package or SDK, be sure it has been
installed.

我必须自己手动安装GLAD包并设置路径吗?我认为vcpkg会为我处理这个问题。如果我误解了什么,请告诉我,因为我是现代cmake和vcpkg的新手。

这个修复了:brew install pkg-config

我得到了更多的描述性错误信息后,我删除了build文件夹。当使用vscode配置cmake时,这个错误信息是隐藏的,但是当通过zsh终端配置时,这个错误信息是可见的。

Building glfw3[core]:arm64-osx...
warning: -- Using community triplet arm64-osx. This triplet configuration is not guaranteed to succeed.
-- [COMMUNITY] Loading triplet configuration from: /Users/munta/Dev/vcpkg/triplets/community/arm64-osx.cmake
-- Downloading https://github.com/glfw/glfw/archive/7482de6071d21db77a7236155da44c172a7f6c9e.tar.gz -> glfw-glfw-7482de6071d21db77a7236155da44c172a7f6c9e.tar.gz...
-- Extracting source /Users/munta/Dev/vcpkg/downloads/glfw-glfw-7482de6071d21db77a7236155da44c172a7f6c9e.tar.gz
-- Using source at /Users/munta/Dev/vcpkg/buildtrees/glfw3/src/172a7f6c9e-7678776297.clean
GLFW3 currently requires the following libraries from the system package manager:
xinerama
xcursor
xorg
libglu1-mesa
pkg-config
These can be installed via brew install libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev pkg-config
-- Configuring arm64-osx
-- Building arm64-osx-dbg
-- Building arm64-osx-rel
-- Fixing pkgconfig file: /Users/munta/Dev/vcpkg/packages/glfw3_arm64-osx/lib/pkgconfig/glfw3.pc
CMake Error at scripts/cmake/vcpkg_find_acquire_program.cmake:619 (message):
Could not find pkg-config.  Please install it via your package manager:
brew install pkg-config
Call Stack (most recent call first):
scripts/cmake/vcpkg_fixup_pkgconfig.cmake:151 (vcpkg_find_acquire_program)
ports/glfw3/portfile.cmake:43 (vcpkg_fixup_pkgconfig)
scripts/ports.cmake:147 (include)

最新更新