我正在尝试使用GLFW3在OpenGL上进行教程。我正在使用Visual Studio Code IDE,并且使用Homebrew安装了GLFW3。
我正在使用此命令g++ -L/usr/local/include OpenGL\ Tutorial/main.cpp
运行程序。
运行该命令后,出现此错误:
Undefined symbols for architecture x86_64: "_glBegin", referenced from: _main in main-b4263d.o "_glClear", referenced from: _main in main-b4263d.o "_glEnd", referenced from: _main in main-b4263d.o "_glVertex2f", referenced from: _main in main-b4263d.o "_glfwCreateWindow", referenced from: _main in main-b4263d.o "_glfwInit", referenced from: _main in main-b4263d.o "_glfwMakeContextCurrent", referenced from: _main in main-b4263d.o "_glfwPollEvents", referenced from: _main in main-b4263d.o "_glfwSwapBuffers", referenced from: _main in main-b4263d.o "_glfwTerminate", referenced from: _main in main-b4263d.o "_glfwWindowShouldClose", referenced from: _main in main-b4263d.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
我正在尝试运行的代码是
#include <iostream>
// #define GLEW_STATIC
// #include <GL/glew.h>
#include <GLFW/glfw3.h>
int main(void)
{
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(1080, 810, "OpenGL Tutorial", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
/* Initialize GLEW */
// if (glewInit() != GLEW_OK)
// std::cout << "Failed to Initialize GLEW!" << std::endl;
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glVertex2f(-0.5f, -0.5f);
glVertex2f(0.0f, 0.5f);
glVertex2f(0.5f, -0.5f);
glEnd();
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}