【问题标题】:Compile OpenGL program in Mac Terminal在 Mac 终端中编译 OpenGL 程序
【发布时间】: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;
}

【问题讨论】:

标签: c++ macos opengl compiler-errors


【解决方案1】:

这只是一个猜测,但请尝试在命令行末尾添加 `-lglfw'。这告诉 g++ 针对 libglfw 进行编译。

【讨论】:

    【解决方案2】:

    错误显示Undefined symbols for architecture x86_64 的事实让我认为您安装的库版本可能是针对 64 位体系结构构建的。请记住,在选择要安装的库时,您应该根据您打算定位的架构选择 32 位或 64 位版本,而不是您的开发机器使用的架构。

    参考this other question

    【讨论】:

    • 好的,但是,可以告诉 g++ 在编译时使用某些架构。你是怎样做的?如果你说-arch i386或-arch x86_64,我用过,还是报同样的错误。
    • @rathorsunpreet 我的意思是问题可能出在您安装的库上,而不是您自己的代码上。重新安装 GLFW 和 GLEW 库,确保安装 32 位版本。
    猜你喜欢
    • 2014-02-05
    • 2013-12-18
    • 2017-06-09
    • 2014-07-21
    • 2015-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-03
    相关资源
    最近更新 更多