将 GLM 添加到 Xcode 4 中的项目
我正在尝试将 GLM 添加到 Xcode 4 中的项目中,但无法编译它。我已通过添加文件对话框将 glm 文件添加到我的项目中。
我遇到词法/预处理器问题,并且 Xcode 找不到文件
。
我不确定我需要调整什么才能构建它。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要做的就是将文件添加到项目中并
#import "glm.hpp"
(对于 Objective-C++;对于简单的 C++,它应该只是#include "glm.hpp" )。
有几件事需要注意:
当您下载 OpenGL 数学库时,它附带了一堆您不需要的东西(测试代码、无关的实用程序)。将这些添加到您的项目中将导致我无法消除的编译错误。您唯一需要的目录是
glm/
目录;您可以删除test/
、util/
、doc/
和bench/
目录。如果您尝试遵循“如何添加 OpenGL”数学 (GLM) 到 Xcode 4?” 并且仍然遇到问题,这可能是困扰您的问题。OpenGL 数学文档告诉您要包含 或 文件。在 Xcode 4 中,您应该包含它们,例如“glm.hpp”或“*.hpp”。无论文件位于项目中的哪个位置,Xcode 都会找到它们。据说您可以添加用户定义的构建设置“USE_HEADERMAP”并将其设置为“NO”以禁用此功能,但我对此没有任何运气。
并且,为了以防万一,请注意,使用 OpenGL 数学库的代码文件必须是 Objective C++ 文件(以“.mm”结尾),而不是默认/纯 Objective C 文件(以“.mm”结尾)在“.m”中)。毕竟它很大程度上是一个 C++ 库...:-)
我希望有所帮助。我自己只是在解决这个问题,而且还没有机会真正推动这个(例如,我基本上只是添加了一两个
mat4
对象并确保东西仍然编译),但它似乎正在发挥作用。All you need to do is add the files to the project and
#import "glm.hpp"
(for Objective-C++; for simple C++ it should just be#include "glm.hpp"
).A couple things to be careful of:
The OpenGL Mathematics library, when you download it, comes with a bunch of stuff you don't need (test code, extraneous utilities). Adding these to your project will result in compile errors which I could not get rid of. The only directory you need is the
glm/
directory; you can delete thetest/
,util/
,doc/
, andbench/
directories. If you were trying to follow "How do I add OpenGL Mathematics (GLM) to Xcode 4?" and were still having problems, this may be the thing which was tripping you up.The OpenGL Mathematics documentation tells you to include the or files. In Xcode 4, you should include them like "glm.hpp" or "*.hpp". Xcode will find the files no matter where in the project they are. Supposedly you can add a user-defined build setting "USE_HEADERMAP" and set it to "NO" to disable this, but I didn't have any luck with that.
And, just in case, note that your code files using the OpenGL Mathematics library must be Objective C++ files (ending in ".mm"), not the default/plain Objective C files (ending in ".m"). It is very much a C++ library after all... :-)
I hope that help. I was just working through this myself, and I haven't had the chance to really push this (e.g. I've basically just added a
mat4
object or two and made sure things still compiled), but it seems to be working.我遇到了同样的问题,我将
ViewController.m
重新管理为ViewController.mm
解决了它。将扩展名更改为.mm
告诉 XCode 该文件内部可能包含 C++ 代码。文章 编写 Object-C 代码在类和对象部分对此进行了解释。I ran into the same problem and I solved it remaning my
ViewController.m
toViewController.mm
. Change the extension to.mm
tells XCode that the file may contain C++ code inside. The article Write Object-C Code explains this in the Classes and Objects section.