1

I tried to download the examples for OpenGL Programming Guide: The Official Guide to Leaning OpenGL, Version 4.5 with SPIR-V and I tried to import the library and include files into my Visual Studio solution so that I can create OpenGL applications with the same file the author used, but I keep on getting these errors:

LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
GLProgram.obj : error LNK2019: unresolved external symbol gl3wInit referenced in function main
GLProgram.obj : error LNK2019: unresolved external symbol LoadShaders referenced in function "void __cdecl init(void)" (?init@@YAXXZ)
GLProgram.obj : error LNK2001: unresolved external symbol gl3wDrawArrays
GLProgram.obj : error LNK2001: unresolved external symbol gl3wBindBuffer
GLProgram.obj : error LNK2001: unresolved external symbol gl3wEnableVertexAttribArray
GLProgram.obj : error LNK2001: unresolved external symbol gl3wUseProgram
GLProgram.obj : error LNK2001: unresolved external symbol gl3wVertexAttribPointer
GLProgram.obj : error LNK2001: unresolved external symbol gl3wClearBufferfv
GLProgram.obj : error LNK2001: unresolved external symbol gl3wBindVertexArray
GLProgram.obj : error LNK2001: unresolved external symbol gl3wGenVertexArrays
GLProgram.obj : error LNK2001: unresolved external symbol gl3wBufferStorage
GLProgram.obj : error LNK2001: unresolved external symbol gl3wCreateBuffers
C:\Users\saada\Desktop\Visual Studio Projects\OpenGL Programming Guide\OpenGL\OpenGL SPIR-V\x64\Debug\OpenGL SPIR-V.exe : fatal error LNK1120: 12 unresolved externals

What I did was set the include and lib folders from the examples download as the include directories for my project, and then downloaded the glfw3.lib file and linked it, but it appears I am missing something for gl3w. How do I fix, am I missing some .lib file? Here is my code just in case you need it:

#include <vgl.h>
#include <LoadShaders.h>

#define BUFFER_OFFSET(a) ((void*)(a))

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)
{
    glGenVertexArrays(NumVAOs, VAOs);
    glBindVertexArray(VAOs[Triangles]);

    GLfloat  vertices[NumVertices][2] = {
        { -0.90f, -0.90f }, {  0.85f, -0.90f }, { -0.90f,  0.85f },  // Triangle 1
        {  0.90f, -0.85f }, {  0.90f,  0.90f }, { -0.85f,  0.90f }   // Triangle 2
    };

    glCreateBuffers(NumBuffers, Buffers);
    glBindBuffer(GL_ARRAY_BUFFER, Buffers[ArrayBuffer]);
    glBufferStorage(GL_ARRAY_BUFFER, sizeof(vertices), vertices, 0);

    ShaderInfo  shaders[] =
    {
        { GL_VERTEX_SHADER, "media/shaders/triangles/triangles.vert" },
        { GL_FRAGMENT_SHADER, "media/shaders/triangles/triangles.frag" },
        { GL_NONE, NULL }
    };

    GLuint program = LoadShaders(shaders);
    glUseProgram(program);

    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(800, 600, "Triangles", NULL, NULL);

    glfwMakeContextCurrent(window);
    gl3wInit();

    init();

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

    glfwDestroyWindow(window);

    glfwTerminate();
}

Thanks in advance.

UPDATE: The solution I found was to, not only use my library folder as an include directory, but also include the folder in my project itself.

Saad Amin
  • 33
  • 2
  • 6
  • You are missing a .lib for gl3w. Sorry I'm not familiar with gl3w but are you sure it isn't glew? Glew is used exactly like you've done here. In case it is glew, see this link for the installation: http://glew.sourceforge.net/install.html then just link it in VS like you did with glfw – Nathan Wride Mar 11 '20 at 23:50
  • The code example in the book had used gl3w only, so I think it can only be gl3w that I'm supposed to use here, not glew. If I use glew, that might not work perfectly with the other files, and I don't think it supports more than OpenGL 3.3, but you can correct me if I'm wrong there. – Saad Amin Mar 12 '20 at 00:03
  • Ah this is interesting, there's an article here supporting what you've just said: https://github.com/ocornut/imgui/issues/880 Have you generated the .h and .c files using this script? https://github.com/skaslev/gl3w/blob/master/gl3w_gen.py It mentions being able to link statically or dynamically so you might be able to look into a static link. – Nathan Wride Mar 12 '20 at 00:08
  • The files were already present when I downloaded the code examples, so I don't think I need to run the script. But I will look into it anyway. – Saad Amin Mar 12 '20 at 00:12
  • Have you made sure to add the .c file to your project? Also try `use /NODEFAULTLIB:library` as suggested in your project settings – Nathan Wride Mar 12 '20 at 00:14
  • 1
    I already did, I found the solution. It was to include my library folder in my project with using it as an include folder. – Saad Amin Mar 12 '20 at 00:35
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Scheff's Cat Mar 12 '20 at 06:49

0 Answers0