为什么C++找不到 GLM 标头?

Why can't C++ find GLM headers?

本文关键字:标头 GLM 找不到 C++ 为什么      更新时间:2023-10-16

我没有权限将 GLM 放入 usr/local/include 或 usr/include 中,但我需要使用 GLM 进行 openGL。代码(我无法更改)像这样查找 GLM:

#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>

文件夹 glm 与我的主目录位于同一目录中.cpp此代码来自该目录。我认为它不起作用,因为它正在 usr/include 中寻找 glm 内置标头中的位置(我使用 redhat linux)

我怎么能阻止这种情况发生,因为我无法运行:

 g++ main.cpp -lGL -lglut -lGLEW

没有这些错误:

main.cpp:46:23: error: glm/glm.hpp: No such file or directory
main.cpp:47:40: error: glm/gtc/matrix_transform.hpp: No such file or directory
main.cpp:48:32: error: glm/gtc/type_ptr.hpp: No such file or directory
main.cpp:62: error: ‘glm’ has not been declared
main.cpp:62: error: expected constructor, destructor, or type conversion before ‘cameraMatrix’
main.cpp: In function ‘int setShaderData(const unsigned int&)’:
main.cpp:102: error: ‘glm’ has not been declared
main.cpp:102: error: expected ‘;’ before ‘projection’
main.cpp:105: error: ‘glm’ has not been declared
main.cpp:105: error: ‘projection’ was not declared in this scope
main.cpp:109: error: ‘glm’ has not been declared
main.cpp:109: error: expected ‘;’ before ‘modelview’
main.cpp: In function ‘void render()’:
main.cpp:187: error: ‘cameraMatrix’ was not declared in this scope
main.cpp:187: error: ‘glm’ has not been declared
main.cpp:200: error: ‘glm’ has not been declared

我的回答与作者的问题并没有真正的关系,但我只是把它留给那些从 ubuntu 来到这里的人,他们缺少一个包

sudo apt-get install libglm-dev

GLM 不是 OpenGL 的一部分。这是一个C++数学库,具有与 GLSL 大致相同的语法。为了使用它,您需要从此处下载它或使用包管理器安装它(尽管如果您在这台计算机上没有管理权限,那么您将无法执行此操作)。

拥有它后,您需要将其添加到包含路径中:

g++ main.cpp -lGL -lglut -lGLEW -I/path/to/glm/headers

尽管如果您使用包管理器安装它,它可能会最终出现在您的系统包含路径中。