cmake config_error ai_generated true

CMake 错误:找不到 GLFW3(缺少:GLFW3_DIR)

CMake Error: Could NOT find GLFW3 (missing: GLFW3_DIR)

ID: cmake/glfw3-not-found-missing-config

其他格式: JSON · Markdown 中文 · English
85%修复率
85%置信度
1证据数
2023-03-01首次发现

版本兼容性

版本状态引入弃用备注
GLFW 3.3 active
GLFW 3.4 active
CMake 3.16 active
CMake 3.20 active

根因分析

CMake 的 find_package(GLFW3) 无法找到 GLFW3Config.cmake 或 glfw3-config.cmake 文件,通常是因为 GLFW3 未安装或安装前缀不在 CMake 搜索路径中。

English

CMake's find_package(GLFW3) cannot locate the GLFW3Config.cmake or glfw3-config.cmake file, typically because GLFW3 is not installed or the install prefix is not in CMake's search path.

generic

官方文档

https://www.glfw.org/docs/latest/build.html

解决方案

  1. 安装开发包:在 Ubuntu/Debian 上:sudo apt-get install libglfw3-dev。在 Fedora 上:sudo dnf install glfw-devel。在 macOS 上:brew install glfw。
  2. 如果从源码构建 GLFW3,运行 cmake 时加上 -DGLFW_BUILD_DOCS=OFF -DGLFW_INSTALL=ON,然后 sudo make install。然后将 GLFW3_DIR 设置为安装前缀(例如 /usr/local/lib/cmake/glfw3)。
  3. 在命令行手动提供 GLFW3_DIR:cmake .. -DGLFW3_DIR=/path/to/glfw3/lib/cmake/glfw3

无效尝试

常见但无效的做法:

  1. 70% 失败

    Some system packages (e.g., libglfw3 on Ubuntu) install only the shared library and headers, not the CMake config file. The config file is in a separate -dev package.

  2. 85% 失败

    GLFW3_DIR must point to the directory containing GLFW3Config.cmake, typically the build or install directory, not the source root.

  3. 60% 失败

    Without REQUIRED, CMake continues but variables like GLFW3_FOUND are FALSE, leading to undefined symbols at link time.