首页 > 解决方案 > 无法在 MacOS10.14 上安装 OpenGL

问题描述

我尝试了很多安装OpenGL的方法,使用自制软件安装glfw和glew:

$ brew install glew glfw3

或者通过源码编译:

$ cd glfw && cmake . && make && sudo make install $ cd glew && make && sudo make install

Xcode 用于创建项目。Opengl.framework、glut.framework、libglfw3。A 和 libglew。A全部添加到项目中。头文件路径为/usr/local/include,库路径为/usr/local/lib。Main.cpp 源代码:

#include <iostream>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
void Render(void)
{
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_TRIANGLES);
    {
        glColor3f(1.0,0.0,0.0);
        glVertex2f(0, .5);
        glColor3f(0.0,1.0,0.0);
        glVertex2f(-.5,-.5);
        glColor3f(0.0, 0.0, 1.0);
        glVertex2f(.5, -.5);
    }
    glEnd();
}
int main(void) {
    GLFWwindow* win;
    if(!glfwInit()){
        return -1;
    }
    win = glfwCreateWindow(640, 480, "OpenGL Base Project", NULL, NULL);
    if(!win)
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }
    if(!glewInit())
    {
        return -1;
    }
    glfwMakeContextCurrent(win);
    while(!glfwWindowShouldClose(win)){
        Render();
        glfwSwapBuffers(win);
        glfwPollEvents();
    }
    glfwTerminate();
    exit(EXIT_SUCCESS);
    return 0;
}

编译错误:

Undefined symbols for architecture x86_64:
... (many can't find errors)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

谁能帮我?

标签: c++xcodeopengl

解决方案


推荐阅读