0

On Windows, I set up Visual Studio 2017 for OpenGL and added Includes and Libraries folders (dedicated for OpenGl_Stuff) to Include Directories and Library Directories and also glfw3.lib opengl32.lib to Additional Dependencies, all to the Properties of the project

Then created an Empty Project named opengl_1 for running this and this codes. They ran successfully.

But there is an issue.
I get these 13 linker errors:

*Severity Code Description Project File Line Suppression State

Error LNK2019 unresolved external symbol _gl3wInit referenced in function _main Opengl_1 C:\Users\Abbasi\documents\visual studio 2017\Projects\Opengl_1\Opengl_1\Main.obj 1*

Error LNK2019 unresolved external symbol _LoadShaders referenced in function "void __cdecl init(void)" (?init@@YAXXZ) Opengl_1 C:\Users\Abbasi\documents\visual studio 2017\Projects\Opengl_1\Opengl_1\Main.obj 1*

Error LNK2001 unresolved external symbol _gl3wDrawArrays Opengl_1 C:\Users\Abbasi\documents\visual studio 2017\Projects\Opengl_1\Opengl_1\Main.obj 1*

Error LNK2001 unresolved external symbol _gl3wBindBuffer Opengl_1 C:\Users\Abbasi\documents\visual studio 2017\Projects\Opengl_1\Opengl_1\Main.obj 1*

Error LNK2001 unresolved external symbol _gl3wEnableVertexAttribArray Opengl_1 C:\Users\Abbasi\documents\visual studio 2017\Projects\Opengl_1\Opengl_1\Main.obj 1*

Error LNK2001 unresolved external symbol _gl3wUseProgram Opengl_1 C:\Users\Abbasi\documents\visual studio 2017\Projects\Opengl_1\Opengl_1\Main.obj 1*

Error LNK2001 unresolved external symbol _gl3wVertexAttribPointer Opengl_1 C:\Users\Abbasi\documents\visual studio 2017\Projects\Opengl_1\Opengl_1\Main.obj 1*

Error LNK2001 unresolved external symbol _gl3wClearBufferfv Opengl_1 C:\Users\Abbasi\documents\visual studio 2017\Projects\Opengl_1\Opengl_1\Main.obj 1*

Error LNK2001 unresolved external symbol _gl3wBindVertexArray Opengl_1 C:\Users\Abbasi\documents\visual studio 2017\Projects\Opengl_1\Opengl_1\Main.obj 1*

Error LNK2001 unresolved external symbol _gl3wGenVertexArrays Opengl_1 C:\Users\Abbasi\documents\visual studio 2017\Projects\Opengl_1\Opengl_1\Main.obj 1*

Error LNK2001 unresolved external symbol _gl3wCreateBuffers Opengl_1 C:\Users\Abbasi\documents\visual studio 2017\Projects\Opengl_1\Opengl_1\Main.obj 1*

Error LNK2001 unresolved external symbol _gl3wNamedBufferStorage Opengl_1 C:\Users\Abbasi\documents\visual studio 2017\Projects\Opengl_1\Opengl_1\Main.obj 1*

Error LNK1120 12 unresolved externals Opengl_1 C:\Users\Abbasi\documents\visual studio 2017\Projects\Opengl_1\Debug\Opengl_1.exe 1*

When I want to run the following code:

#include <iostream>
using namespace std;
#include "vgl.h"
#include "LoadShaders.h"

enum VAO_IDs { Triangles, NumVAOs };
enum Buffer_IDs { ArrayBuffer, NumBuffers };
enum Attrib_IDs { vPosition = 0 };
GLuint VAOs[NumVAOs];
GLuint Buffers[NumBuffers];
const GLuint NumVertices = 6;
//--------------------------------------------------------------------
//
// init
//
void
init(void)
{
    static const GLfloat vertices[NumVertices][2] =
    {
        { -0.90, -0.90 }, // Triangle 1
        { 0.85, -0.90 },
        { -0.90, 0.85 },
        { 0.90, -0.85 }, // Triangle 2
        { 0.90, 0.90 },
        { -0.85, 0.90 }
    };
    glCreateBuffers(NumBuffers, Buffers);
    glNamedBufferStorage(Buffers[ArrayBuffer], sizeof(vertices),
        vertices, 0);
    ShaderInfo shaders[] = {
        { GL_VERTEX_SHADER, "triangles.vert" },
        { GL_FRAGMENT_SHADER, "triangles.frag" },
        { GL_NONE, NULL }
    };
    GLuint program = LoadShaders(shaders);
    glUseProgram(program);
    glGenVertexArrays(NumVAOs, VAOs);
    glBindVertexArray(VAOs[Triangles]);
    glBindBuffer(GL_ARRAY_BUFFER, Buffers[ArrayBuffer]);
    glVertexAttribPointer(vPosition, 2, GL_FLOAT,
        GL_FALSE, 0, BUFFER_OFFSET(0));
    glEnableVertexAttribArray(vPosition);
}
//--------------------------------------------------------------------
//
// display
//
void
display(void)
{
    static const float black[] = { 0.0f, 0.0f, 0.0f, 0.0f };
    glClearBufferfv(GL_COLOR, 0, black);
    glBindVertexArray(VAOs[Triangles]);
    glDrawArrays(GL_TRIANGLES, 0, NumVertices);
}
//--------------------------------------------------------------------
//
// main
//
int
main(int argc, char** argv)
{
    glfwInit();
    GLFWwindow* window = glfwCreateWindow(640, 480, "Triangles", NULL,
        NULL);
    glfwMakeContextCurrent(window);
    gl3wInit();
    init();

    while (!glfwWindowShouldClose(window))
    {
        display();
        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    glfwDestroyWindow(window);
    glfwTerminate();
}

How to solve this please?

Gilles Gouaillardet
  • 8,193
  • 11
  • 24
  • 30
Franky
  • 1,181
  • 2
  • 11
  • 33
  • `gl3wInit` is neither from OpenGL directly nor from glfw. If you want to use it, link against the library where it comes from. It also seems that you don't have an implementation of the LoadShader method in your project. – BDL Oct 06 '17 at 09:26
  • 1
    please copy/paste the error message. otherwise your question cannot be correctly indexed and is helpless for other users facing the same issue – Gilles Gouaillardet Oct 06 '17 at 09:32
  • 1
    @GillesGouaillardet: sorry for inconvenient. I edited the question. – Franky Oct 06 '17 at 10:23
  • @BDL: The book *OpenGL.Programming.Guide.9th.Edition* declares this code in page 40 as *Example1.1*. – Franky Oct 06 '17 at 10:25
  • If possible, please test that code on your Visual Studio to know if the issue is related to the code or VS. – Franky Oct 06 '17 at 11:01
  • I solved the problem, and will provide an answer soon for those who have that problem too. – Franky Oct 06 '17 at 13:03

0 Answers0