很多未定义的符号 - GLFW

时间:2014-04-12 11:00:08

标签: c++ xcode macos opengl glfw

我已经在我的Mac上下载了glfw并决定开始尝试。我通过使用cmake生成unix makefile来安装它,然后运行make && make install。我也做了brew install glfw3并开始工作。

我做的第一件事是转到InitWithData的FPS教程编号1.编码,编译它,工作正常。但是当我去教程3时,我的xcode开始讨论Undefined symbols for architecture x86_64: 我试着回溯到第一个教程,但后来它似乎已经腐败了。然后我在glfw 3文档上查看了本教程并找到了这段代码。

#include <GLFW/glfw3.h>
#include <stdlib.h>
#include <stdio.h>
static void error_callback(int error, const char* description)
{
    fputs(description, stderr);
}
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
    if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
        glfwSetWindowShouldClose(window, GL_TRUE);
}
int main(void)
{
    GLFWwindow* window;
    glfwSetErrorCallback(error_callback);
    if (!glfwInit())
    exit(EXIT_FAILURE);
    window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }
    glfwMakeContextCurrent(window);
    glfwSetKeyCallback(window, key_callback);
    while (!glfwWindowShouldClose(window))
    {
        float ratio;
        int width, height;
        glfwGetFramebufferSize(window, &width, &height);
        ratio = width / (float) height;
        glViewport(0, 0, width, height);
        glClear(GL_COLOR_BUFFER_BIT);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(-ratio, ratio, -1.f, 1.f, 1.f, -1.f);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glRotatef((float) glfwGetTime() * 50.f, 0.f, 0.f, 1.f);
        glBegin(GL_TRIANGLES);
        glColor3f(1.f, 0.f, 0.f);
        glVertex3f(-0.6f, -0.4f, 0.f);
        glColor3f(0.f, 1.f, 0.f);
        glVertex3f(0.6f, -0.4f, 0.f);
        glColor3f(0.f, 0.f, 1.f);
        glVertex3f(0.f, 0.6f, 0.f);
        glEnd();
        glfwSwapBuffers(window);
        glfwPollEvents();
    }
    glfwDestroyWindow(window);
    glfwTerminate();
    exit(EXIT_SUCCESS);
}

但是,它仍然不起作用。有这些错误:

Undefined symbols for architecture x86_64:
  "_glfwCreateWindow", referenced from:
      _main in main.o
  "_glfwDestroyWindow", referenced from:
      _main in main.o
  "_glfwGetFramebufferSize", referenced from:
      _main in main.o
  "_glfwGetTime", referenced from:
      _main in main.o
  "_glfwInit", referenced from:
      _main in main.o
  "_glfwMakeContextCurrent", referenced from:
      _main in main.o
  "_glfwPollEvents", referenced from:
      _main in main.o
  "_glfwSetErrorCallback", referenced from:
      _main in main.o
  "_glfwSetKeyCallback", referenced from:
      _main in main.o
  "_glfwSetWindowShouldClose", referenced from:
      key_callback(GLFWwindow*, int, int, int, int) in main.o
  "_glfwSwapBuffers", referenced from:
      _main in main.o
  "_glfwTerminate", referenced from:
      _main in main.o
  "_glfwWindowShouldClose", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

任何人都知道发生了什么事吗?我已经尝试过重新安装glfw了。 (请记住,xcode4 -macosx

1 个答案:

答案 0 :(得分:0)

好。好吧,似乎我已经解决了我的问题。我不知道为什么,但是......

deleted libglfw.dylib
deleted unix makefile installed headers
recreated libglfw.a (portable, non system)
added all the dependencies (cocoa, iokit, corevideo, opengl)

我不知道为什么dylibs和makefile生成的东西不起作用。如果有人能解释为什么......