Я пытаюсь следовать руководству по OpenGL с GLFW3. Я использую Visual Studio Code IDE и установил GLFW3 с помощью Homebrew.
Я запускаю свою программу с этой командой 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;
}