【发布时间】:2014-12-16 03:25:46
【问题描述】:
我正在使用 Mac Os X 10.9.5 完全更新了 XCode 版本 6.0.1。我还安装了安装 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;
}
【问题讨论】:
-
你没有链接到 glfw 库,只有新的链接目录,但没有库。
-
使用 -L/usr/local/lib 告诉 GLFW 库。所有库都由 -L 指定。
标签: c++ macos opengl compiler-errors