GLFW 库的 Xcode 项目设置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/777111/
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-09-14 18:32:30  来源:igfitidea点击:

Xcode project setup for GLFW library

xcodeopenglglfw

提问by Adam Taylor

I'm working on an assignment which is to simulate the beginning of the universe using C and OpenGL/GLFW.

我正在做一项任务,即使用 C 和 OpenGL/GLFW 模拟宇宙的开始。

I'm pretty new to C and also to Xcode, which is not helping at all. I've overcome my silly compilation problems and the code is finding GL/glfw.h ok. When I compile and run I receive a "Visualisation [name of the project] has exited with status 5".

我对 C 和 Xcode 都很陌生,这根本没有帮助。我已经克服了我愚蠢的编译问题,代码发现 GL/glfw.h 没问题。当我编译并运行时,我收到“可视化 [项目名称] 已退出,状态为 5”。

I wasn't really sure what that meant but if I try and run the code from the command line I get the following error:

我不太确定这意味着什么,但是如果我尝试从命令行运行代码,我会收到以下错误:

ADAM:Debug adam$ ./Visualisation 
dyld: Library not loaded: @executable_path/libglfw.dylib
Referenced from: /Users/adam/Documents/Programming/C/Visualisation/build/Debug/./Visualisation
Reason: image not found
Trace/BPT trap

I added libglfw.dylib to the project the same way I added libglfw.a to see if that fixed it and no, it didn't.

我将 libglfw.dylib 添加到项目中的方式与添加 libglfw.a 的方式相同,以查看是否修复了它,不,它没有。

I can't figure out where @executable_path is set or what it is set to but inside the build settings for the project in Library Search Paths is "$(SRCROOT)/../../../../glfw/lib/macosx" which is where this library resides.

我无法弄清楚@executable_path 的设置位置或设置的内容,但在库搜索路径中项目的构建设置中,“$(SRCROOT)/../../../../glfw/ lib/macosx”,这是该库所在的位置。

I checked that the library was executable and it is, do I need to set that library path somewhere else?

我检查了库是可执行的,是的,我是否需要在其他地方设置该库路径?

回答by Nicola

I have the same problem, i'm using Xcode 4.3.2 on a Macbookpro with Osx Lion 10.7.4.

我有同样的问题,我在带有 Osx Lion 10.7.4 的 Macbookpro 上使用 Xcode 4.3.2。

1 - Install the GLFW library, please visit http://www.glfw.org/.
3 - Be sure you have added in your link binary with librariesoption under the build phasesOpenGLand Cocoaframework.
2 - Import libglfw.ain your Xcode project, using the project navigator.
4 - Now in your project navigator, inside Productsdirectory right click on your_app_name file and select show in finder, copy the libglfw.dylibinside it.

1 - 安装 GLFW 库,请访问http://www.glfw.org/
3 - 确保您在构建阶段OpenGLCocoa框架下添加了带有库选项的链接二进制文件。 2 -使用项目导航在您的 Xcode 项目中导入libglfw.a。 4 - 现在在您的项目导航器中,在Products目录中右键单击 your_app_name 文件并选择在 finder 中显示,复制其中的libglfw.dylib

回答by Lyndsey Ferguson

The first thing I would like to say is that you need to read the Xcode manual, this question is answered there (and you may have other questions which will also be answered there).

我想说的第一件事是你需要阅读 Xcode 手册,这个问题在那里得到了回答(你可能还有其他问题也会在那里得到回答)。

To find the manual, launch Xcode and select "Xcode Workspace Guide" from the "Help" menu.

要查找手册,请启动 Xcode 并从“帮助”菜单中选择“Xcode Workspace Guide”。

To answer the question, the application is looking for the library in the same directory as the application's executable. If I understand what you're doing, you've made a command-line application, the directory that contains Visualisation should also contain libglfw.dylib. @executable_path is /path/to/Visualisation.

为了回答这个问题,应用程序正在与应用程序的可执行文件相同的目录中寻找库。如果我理解你在做什么,那么你已经创建了一个命令行应用程序,包含 Visualization 的目录也应该包含 libglfw.dylib。@executable_path 是 /path/to/Visualisation。

If this was a typical application with a GUI interface, the path would probably be /path/to/VisualisationApplication.app/Contents/MacOS/Visualisation.

如果这是具有 GUI 界面的典型应用程序,则路径可能是 /path/to/VisualisationApplication.app/Contents/MacOS/Visualisation。