Klotz Großer
Klotz Großer

Reputation: 73

Compiling error lnk 2019 under visual studio

I do not know what to with this error. I searched for some solutions, but nothing helps.

Linker Error:

"error LNK2019: unresolved external symbol __ imp__glDrawArrays"

Source Code:

#include <stdio.h>
#include <stdlib.h>
#include <GL\glew.h>
#include <GLFW\glfw3.h>

int main()
{
    if(glfwInit()==false){
        //Did not succeed
        fprintf(stderr, "GLFW faild ");
        return -1;
    }
    glfwWindowHint(GLFW_SAMPLES,4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR,3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);


    GLFWwindow* window;
    window = glfwCreateWindow(640,480,"Hallo Welt",NULL,NULL);
    if(!window)
    {
        fprintf(stderr, "Window failed");
        glfwTerminate();

        return -1;
    }
    glfwMakeContextCurrent(window);
    glewExperimental = true;
    if(glewInit() !=  GLEW_OK)
    {
        fprintf(stderr, "glew init failed");
        glfwTerminate();
        return -1;
    }

    GLuint vaoID; //Vertex array erzeugt
    glGenVertexArrays(1, &vaoID);
    glBindVertexArray(vaoID); // wir verwenden das VA

    static const GLfloat verts[] = {
        -1.0f,-1.0f,0.0f,
        1.0f,-1.0f,0.0f,
        0.0f,1.0f,0.0f};
    //Generate VBO
    GLuint vboID;
    glGenBuffers(1, &vboID);
    glBindBuffer(GL_ARRAY_BUFFER,vboID);

    glBufferData(GL_ARRAY_BUFFER,sizeof(verts),verts,GL_STATIC_DRAW);



    do{
        glDisableVertexAttribArray(0);
        glBindBuffer(GL_ARRAY_BUFFER,vboID);
        glVertexAttribPointer(0, 3,GL_FLOAT,GL_FALSE,0,(void*)0);

        glDrawArrays(GL_TRIANGLES,0,3);
        glDisableVertexAttribArray(0);

        glfwSwapBuffers(window);
        glfwPollEvents();
    } while(glfwWindowShouldClose(window)==false);

    return 0;
}

I set my directories for my include and lib files. Under Linker->Input i have glew32.lib, glew32s.lib, glfw3dll.lib

If I delete the function glDrawArrays the code works and i get the black window. But I want to draw a white triangle in the window.

Upvotes: 0

Views: 291

Answers (1)

Andon M. Coleman
Andon M. Coleman

Reputation: 43319

You have a couple of problems here:

  1. You are linking to glew32.lib (dynamic --> DLL) and glew32s.lib (static)

    • Pick only one, and I would suggest glew32s.lib - but make sure you add GLEW_STATIC to pre-processor definitions when you use glew32s.lib.

  2. You are only linking to support libraries, not the actual OpenGL run-time that ships with Windows

    • Fix this by adding OpenGL32.lib to your libraries.

Upvotes: 1

Related Questions