为什么 C++ 找不到 GLM 头文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28977455/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 21:07:58  来源:igfitidea点击:

Why can't C++ find GLM headers?

c++opengldirectorydirectory-structureglm-math

提问by Barney Chambers

I do not have permissions to put GLM into usr/local/include or usr/include but I need to use GLM for openGL. The code (I am not able to change) looks for GLM like this:

我没有将 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>

the folder glm is in the same directory as my main.cpp where this code is from. I think it's not working because it's looking for glm in usr/include where in built headers are (im using redhat linux)

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

How can I stop this from happening, since I cannot run:

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

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

without these errors:

没有这些错误:

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

回答by SerCe

My answer isn't really related to the author's question, but I'm just leaving it here for those, who come here from ubuntu with a missing package

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

sudo apt-get install libglm-dev

回答by Jherico

GLM is not part of OpenGL. It's a C++ math library that has much of the same syntax as GLSL. In order to use it you need to download it from hereor install it using your package manager (although if you don't have administrative rights on this machine, then you won't be able to do that).

GLM 不是 OpenGL 的一部分。它是一个 C++ 数学库,与 GLSL 的语法有很多相同。为了使用它,您需要从这里下载它或使用您的包管理器安装它(尽管如果您在这台机器上没有管理权限,那么您将无法这样做)。

Once you have it, you need to add it to your include path:

获得后,您需要将其添加到包含路径中:

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

Although if you install it with a package manager it will probably end up in your system include path.

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