在Mac终端上编译OpenGL程序
Compile OpenGL program in Mac Terminal
我使用的是完全更新了XCode 6.0.1版本的Mac Os X 10.9.5。我还安装了在安装XCode之后必须安装的命令行实用程序。我在我的openGL库中使用GLFW和GLEW。GLEW是手动安装的,而GLFW是用Macports安装的。
我想在没有XCode的情况下进行编码,因为我一直在Windows(使用MingW)和Linux上进行编码。我在谷歌上搜索了如何编译这个程序,还搜索了stackoverflow。
因此,当前我的编译命令如下(这是一个C++程序)
g++ -framework Cocoa -framework OpenGL -framework CoreFoundation -framework CoreVideo -framework IOKit -L/usr/lib -L/usr/local/lib -I/usr/include/GLFW -I/usr/local/include/GL main.cpp -o main
我不断得到以下错误:
Undefined symbols for architecture x86_64:
"_glfwCreateWindow", referenced from:
_main in main-ba7a57.o
"_glfwInit", referenced from:
_main in main-ba7a57.o
"_glfwMakeContextCurrent", referenced from:
_main in main-ba7a57.o
"_glfwTerminate", referenced from:
_main in main-ba7a57.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
程序是:
#define GLEW_STATIC
#include <glew.h>
#include <glfw3.h>
#include <iostream>
using namespace std;
int main(int argc, char* argv[]) {
GLFWwindow* window;
if(!glfwInit()) exit(EXIT_FAILURE);
window = glfwCreateWindow(1024, 768, "glfw", NULL, NULL);
if(!window) {
glfwTerminate();
exit(EXIT_FAILURE);
}
glfwMakeContextCurrent(window);
const GLubyte* version = glGetString(GL_VERSION);
cout << "OpenGL version: " << version << endl;
glfwTerminate();
return 0;
}
这只是猜测,但请尝试在命令行末尾添加"-lglfw"。这个命令告诉g++根据libglfw进行编译。
错误显示Undefined symbols for architecture x86_64
这一事实让我认为您安装的库的版本可能是针对64位体系结构构建的。请记住,在选择要安装的库时,您应该根据要针对的体系结构而不是开发机器使用的体系结构来选择32位或64位版本。
请参阅其他问题以供参考。
相关文章:
- 如何使实例化在我的 OpenGL 程序中工作?
- OpenGL程序不显示三角形
- C++ 如何在 OpenGL 程序中远程调用控制台窗口
- 您是否必须在 OpenGL 程序中调用 glfwSwapInterval(1)?
- 如何在 debian 下正确链接一个 opengl 程序?
- 无法与 mingw 交叉编译 opengl 程序
- OpenGL 程序无法链接?
- OpenGL 程序着色器链接错误
- OpenGL程序不显示任何图片
- 在 MacOSX 上编译 OpenGL 程序时出错('ld:找不到 -lopengl32 的库)
- 带有张量流的OpenGL程序C++对cuInit进行了失败的调用:CUDA_ERROR_OUT_OF_MEMORY
- 无法在Linux Minut中运行简单的OpenGL程序
- 无法将 Linux openGL 程序与 mingw32 交叉编译。配置.log错误:未定义对"_glEnable"的引用
- 当窗口聚焦时,OpenGL程序不会循环
- 如何从 OpenGL 程序中删除未使用的资源
- OpenGL程序在Qt Creator中没有启动
- GLSDK - 无法执行示例 OpenGL 程序
- 如何将.ray文件添加到opengl程序中
- 为什么这个C++/OpenGL程序运行两次
- Qt 5.5和OpenGL:程序在没有任何明显原因的情况下表现得很奇怪