cmake config_error ai_generated true

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

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

Also available as: JSON · Markdown · 中文
85%Fix Rate
85%Confidence
1Evidence
2023-03-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
GLFW 3.3 active
GLFW 3.4 active
CMake 3.16 active
CMake 3.20 active

Root Cause

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

中文

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

Official Documentation

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

Workarounds

  1. 90% success Install the development package: On Ubuntu/Debian: sudo apt-get install libglfw3-dev. On Fedora: sudo dnf install glfw-devel. On macOS: brew install glfw.
    Install the development package: On Ubuntu/Debian: sudo apt-get install libglfw3-dev. On Fedora: sudo dnf install glfw-devel. On macOS: brew install glfw.
  2. 85% success If building GLFW3 from source, run cmake with -DGLFW_BUILD_DOCS=OFF -DGLFW_INSTALL=ON and then sudo make install. Then set GLFW3_DIR to the install prefix (e.g., /usr/local/lib/cmake/glfw3).
    If building GLFW3 from source, run cmake with -DGLFW_BUILD_DOCS=OFF -DGLFW_INSTALL=ON and then sudo make install. Then set GLFW3_DIR to the install prefix (e.g., /usr/local/lib/cmake/glfw3).
  3. 80% success Provide GLFW3_DIR manually on command line: cmake .. -DGLFW3_DIR=/path/to/glfw3/lib/cmake/glfw3
    Provide GLFW3_DIR manually on command line: cmake .. -DGLFW3_DIR=/path/to/glfw3/lib/cmake/glfw3

中文步骤

  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

Dead Ends

Common approaches that don't work:

  1. 70% fail

    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% fail

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

  3. 60% fail

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