Fix “Fatal Error: glm/glm.hpp: No Such File or Directory”
This error means the C++ compiler cannot find GLM’s header files in its include search paths. The fix is usually to install or vendor GLM, then point the compiler at the directory that directly contains the glm folder, not at the glm folder itself. Because GLM is header-only, this is an include-path problem, not a linker problem.
Use this table to identify the most likely cause before changing build settings.
| Symptom | Likely Cause | Fix |
|---|---|---|
glm/glm.hpp does not exist anywhere in the project or system include folders |
GLM is not installed or vendored | Install GLM or add it as a project dependency |
glm/glm.hpp exists, but compilation still fails |
The compiler was given the wrong include root | Add the folder directly above glm to the include path |
CMake says it cannot find glm |
GLM’s CMake package configuration is unavailable or outside CMake’s search paths | Install a development package, provide a prefix, or vendor GLM |
| Your editor reports the error but the build succeeds | IntelliSense or the language server has separate include settings | Configure the editor from the real build configuration |
| It works locally but fails in Docker, CI, WSL, or a remote build | GLM exists on the host but not in the build environment | Add GLM to that environment’s dependency setup |
What the GLM Header Error Means
When the compiler reads this include:
#include <glm/glm.hpp>
it searches each configured include directory for this relative path:
glm/glm.hpp
So the include directory must be the parent directory of glm.
For example, this layout is correct:
project/
├── include/
│ └── glm/
│ └── glm.hpp
└── main.cpp
The compiler needs project/include as an include directory. It will then find:
project/include/glm/glm.hpp
A common mistake is adding project/include/glm instead. With #include <glm/glm.hpp>, that makes the compiler search for a nonexistent nested path:
project/include/glm/glm/glm.hpp
The include directive and the include-directory root must match exactly.
GLM is a header-only library. You normally do not need to add a linker flag such as -lglm, copy a binary library into a system folder, or run a linker-cache command. Those actions cannot fix a missing glm/glm.hpp header.
How to Fix the GLM Include Error
Step 1: Check Whether the Header Actually Exists
First, determine whether GLM is present in your project or installed on the machine.
From a project directory on Linux or macOS, search for the expected header path:
find . -type f -path '*/glm/glm.hpp'
A vendored GLM checkout commonly looks like this:
project/
├── third_party/
│ └── glm/
│ └── glm/
│ └── glm.hpp
└── src/
└── main.cpp
If the search finds no glm/glm.hpp file, add GLM to the project before changing compiler flags. One straightforward option is to clone it into a third-party directory:
git clone https://github.com/g-truc/glm.git third_party/glm
That checkout places the header at:
third_party/glm/glm/glm.hpp
In that layout, third_party/glm is the include root.
For a system installation, use your platform’s GLM development package. On Debian- and Ubuntu-based systems, the package is commonly named libglm-dev. After installation, confirm that the installed location contains a glm directory with glm.hpp inside it.
Step 2: Keep the Standard Include Statement
Use GLM’s normal include form:
#include <glm/glm.hpp>
Add other GLM headers only when your code needs them:
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
Do not “fix” the error by changing the include to a machine-specific relative path such as this:
#include "../../third_party/glm/glm/glm.hpp"
That may compile on one computer but breaks when the file moves, another target uses the code, or CI builds the project from a different directory. Keep the portable glm/... include and fix the build configuration instead.
Step 3: Add the Correct Include Directory
If your project contains this path:
include/glm/glm.hpp
compile with the common include-directory option:
c++ main.cpp -I include/ -o app
The -I include/ option tells GCC or Clang to search include/ for headers. Confirm that the directory passed with -I directly contains the glm folder in your project or installed GLM location.
For a cloned dependency at third_party/glm/glm/glm.hpp, use this include root:
c++ main.cpp -I third_party/glm -o app
For Microsoft’s compiler, the equivalent include option is /I:
cl /I third_party\glm main.cpp
If the include path contains spaces, quote it:
c++ main.cpp -I "/path with spaces/third_party/glm" -o app
Avoid adding header paths to linker settings such as LDFLAGS, target_link_libraries() with a file path, or IDE linker input fields. Header lookup occurs before linking.
Step 4: Configure GLM Through CMake
If your project uses CMake and GLM is installed as a CMake package, use its imported target rather than manually adding global include directories:
find_package(glm CONFIG REQUIRED)
target_link_libraries(my_app PRIVATE glm::glm)
Replace my_app with the executable or library target created by your project. Keep this dependency declaration with the target that uses GLM.
If GLM is vendored at third_party/glm, and you do not have a package configuration available, add the include root to the target directly:
target_include_directories(my_app PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/third_party/glm"
)
Use one approach for the dependency: an installed glm::glm target or a local include directory. Mixing both can hide which copy of GLM the project is actually compiling against.
After changing CMake configuration, configure and build again:
cmake -S . -B build
cmake --build build
Step 5: Rebuild the Actual Target
A successful one-line compiler test does not help if your IDE, Makefile, CMake preset, Docker image, or CI pipeline uses a different compile command. Rebuild the target that originally produced the error.
For Make-based projects, put include paths in CPPFLAGS or the project’s compiler flags, not in linker flags:
CPPFLAGS += -Ithird_party/glm
For an IDE project, add the include root to the C++ compiler’s additional include directories for the active build configuration and platform. Debug and Release configurations, as well as x64 and ARM configurations, can have separate settings.
Fixing GLM in Common Build Environments
Configure GLM in the same environment and build configuration that runs the compiler, whether through CMake, compiler commands, editors, or remote builds.
CMake Projects
Prefer this when GLM was installed by a package manager and CMake can locate its package files:
find_package(glm CONFIG REQUIRED)
target_link_libraries(my_app PRIVATE glm::glm)
If CMake cannot find GLM after installation, the package may be outside its default search locations. Provide the installation prefix through your build configuration, or vendor GLM in the repository so the project controls its own dependency location.
Do not solve a find_package(glm) failure by hard-coding a path to glm.hpp in several source files. Fix CMake’s dependency declaration once, then let targets inherit the required include path.
Makefiles and Direct Compiler Commands
For a direct compiler command, use the parent of the glm directory:
c++ src/main.cpp -Ithird_party/glm -o app
For a project include directory containing include/glm/glm.hpp, use:
c++ src/main.cpp -I include/ -o app
Relative paths are resolved from the directory where the compiler command runs. If your build tool runs commands from a separate build directory, an absolute path or a build-system variable is usually safer.
Visual Studio, VS Code, and Other Editors
An editor’s red underline is not necessarily the compiler’s result.
If the command-line or CMake build succeeds but the editor still reports glm/glm.hpp as missing, configure the editor’s language service from the same build configuration. For example, point it at your generated compile database or CMake project rather than manually maintaining a second list of include directories.
If both the editor and compiler fail, fix the compiler configuration first. The real build command is the source of truth.
Docker, CI, WSL, and Remote Builds
A dependency installed on your host machine is not automatically present inside a container, a CI runner, WSL distribution, or remote build machine.
Add GLM installation or vendoring to the environment that runs the compiler. A project that depends on a manually installed host header will often fail as soon as another developer or CI builds it.
I reproduce this kind of issue in a clean container or virtual environment because it reveals whether the dependency is declared by the project rather than supplied by the host machine.
When GLM Is Installed but Still Cannot Be Found
The Compiler Is Not Receiving the Flag You Added
A project can be compiled through a different build path than the build file you updated. For example, you may edit a Makefile but build through CMake, or configure an IDE while CI runs a shell script.
Inspect the full compiler command emitted by the failing build. Look for an include argument that points to the directory directly above glm. If it is absent, your changed setting is not being used.
If it is present but points to the wrong directory, correct the path rather than adding more -I flags at random.
The Build Cache Is Stale
CMake and IDEs cache configured dependency locations. If you installed or moved GLM after an earlier failed configuration, rerun configuration. If the project still uses an old path, remove the generated build directory and configure from scratch.
A clean configuration is especially useful after changing CMAKE_PREFIX_PATH, switching compilers, moving a vendored dependency, or changing between system-installed and local copies of GLM.
The Header Name or Directory Case Is Wrong
Linux and most container environments are case-sensitive. These are different paths:
glm/glm.hpp
GLM/glm.hpp
glm/GLM.hpp
Use lowercase glm and lowercase glm.hpp exactly as shown in the include directive. A project that appears to work on a case-insensitive filesystem can fail in Linux CI.
The Project Needs a Different GLM Version
Once the compiler finds glm/glm.hpp, later errors about missing functions, changed types, templates, or unsupported compiler features are a different problem. They usually indicate that the project expects a different GLM release or a different C++ language standard.
Match the version specified by the project’s lockfile, package manifest, submodule revision, or documented build requirements. Do not replace a project’s pinned local copy with an unrelated system version unless you are also updating the project for that version.
The Error Is Actually About an Experimental Extension
A message mentioning GLM_GTX_* and GLM_ENABLE_EXPERIMENTAL is not a missing-header error. It means GLM found the extension header, but the extension requires an opt-in macro.
Define the macro before including the experimental extension:
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/gtx/string_cast.hpp>
The definition must be visible before the extension header is included in that translation unit. It will not fix fatal error: glm/glm.hpp: No such file or directory.
How to Confirm the Fix and Prevent It From Returning
Create a minimal source file named glm_smoke.cpp:
#include <glm/glm.hpp>
int main() {
glm::vec3 position(1.0f, 2.0f, 3.0f);
return position.x == 1.0f ? 0 : 1;
}
If your headers are in include/glm/glm.hpp, compile it with:
c++ glm_smoke.cpp -I include/ -o glm_smoke
If that succeeds, the compiler can find GLM. Any remaining failure in the main project is then likely caused by a different build target, an omitted dependency declaration, a version mismatch, or an unrelated compile error.
To keep the fix stable:
- Declare GLM in the project build system rather than relying on a manually configured IDE path.
- Keep vendored dependencies under a predictable directory such as
third_party/glm. - Pin the GLM version when reproducible builds matter.
- Build in a clean environment before assuming a host-installed dependency is sufficient.
- Keep
#include <glm/...>statements portable and avoid machine-specific relative paths.
Frequently Asked Questions
Do I need to link against GLM?
No. GLM is header-only, so #include <glm/glm.hpp> requires a valid include path but normally does not require a separate GLM linker library. Add linker settings only for other libraries your graphics project uses, such as a windowing or OpenGL loader library.
Why does -I.../glm not work?
It usually fails because #include <glm/glm.hpp> makes the compiler append glm/glm.hpp to every include root. If the header is at include/glm/glm.hpp, use -I include/; using -I include/glm makes the compiler look for include/glm/glm/glm.hpp.
Why does it build locally but fail in Docker or CI?
Docker and CI use separate filesystems and often start from a minimal environment. GLM must be installed, copied, or fetched within the image or runner that executes the compiler, and the build configuration there must receive the correct include root.
Does GLM_ENABLE_EXPERIMENTAL fix this error?
No. GLM_ENABLE_EXPERIMENTAL only enables selected glm/gtx/... extension headers after GLM has already been found. For fatal error: glm/glm.hpp: No such file or directory, first ensure that the compiler can locate the directory containing glm/glm.hpp.
What should I do if CMake cannot find GLM?
Install or vendor GLM, then declare it with find_package(glm CONFIG REQUIRED) and link glm::glm to the target. If the package is installed in a nonstandard prefix, configure CMake with that prefix available to its package search paths, or use a project-local GLM checkout and add its parent directory as a target include directory.
