Ошибка компоновщика в Dev C++: неопределенная ссылка на glfwInit

Я пытаюсь следовать этому руководству для OpenGL. Первоначально я скопировал код вручную, но это не сработало, поэтому я скопировал код прямо с веб-сайта. Я продолжаю получать эту ошибку:

[Linker error] undefined reference to 'glfwInit'

из этого кода (который кажется дольше, чем необходимо):

//C++ standard headers
#include <stdio.h>
#include <stdlib.h>
//GLEW header
#include <GL/glew.h>
//GLFW header
#include <GL/glfw3.h>

int main()
{
    if (!glfwInit())
    {
        fprintf(stderr, "Failed to initialize GLFW\n");
        return -1;
    }
    glfwWindowHint(GLFW_SAMPLES, 4); // 4x antialiasing
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // We want OpenGL 3.3
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL 

    // Open a window and create its OpenGL context 
    GLFWwindow* window; // (In the accompanying source code, this variable is global) 
    window = glfwCreateWindow( 1024, 768, "Tutorial 01", NULL, NULL); 
    if( window == NULL )
    {
        fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
            glfwTerminate();
                return -1;
    }
    glfwMakeContextCurrent(window); // Initialize GLEW 
    glewExperimental=true; // Needed in core profile 
    if (glewInit() != GLEW_OK)
    {
        fprintf(stderr, "Failed to initialize GLEW\n");
        return -1;
    }
    // Ensure we can capture the escape key being pressed below
    glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);

    do{
    // Draw nothing, see you in tutorial 2 !

    // Swap buffers
    glfwSwapBuffers(window);
    glfwPollEvents();

    }
    // Check if the ESC key was pressed or the window was closed
    while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
    glfwWindowShouldClose(window) == 0 );
}

Я понятия не имею, почему он не компилируется. Кто-нибудь знает, что происходит?
РЕДАКТИРОВАТЬ: я использую Dev-C++, как указано в названии.

1 ответ

undefined reference to 'glfwInit'

означает, что компоновщик не нашел библиотеку, в которой glfwInit() определено. Вы должны добавить glfw3.a на ваш вход компоновщика. Действительно, Dev-C++ использует MinGW, поэтому в отличие от Visual Studio, библиотеки не могут быть .lib,

Чтобы сделать это с помощью Dev-C++, перейдите в раздел "Параметры проекта", "Параметры" и "Добавить библиотеку". Затем просмотрите проводник, чтобы найти glfw3.a Я упоминал (обычно в GLFW-<version>/lib/).

Другие вопросы по тегам