Reputation: 33
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.
Upvotes: 1
Views: 380
Reputation: 1
I know the question is old but I'd like to offer some insights. I develop my software using Windows 11 with an NVidia 4070ti graphics card.
I read in the redbook (Version 4.5 with SPIR-V) that the examples use gl3w and glfw. So, the first think I did was to get those libraries.
Both come with CMakeLists.txt. One would think that cmake is used to build the libraries. This is only true for glfw.
For gl3w, there is a python script called gl3w_gen.py. Run that script to generate the following files:
gl3w.c GL\gl3.h GL\glcorearb.h KHR\khrplatform.h
I placed gl3w.c in my project and specified the path to the include directory for the headers.
For glfw, go to the build directory which will be empty and execute cmake. For example:
cmake -G "Visual Studio 16 2019" ..
I actually use Visual Studio 2022. So, the command for me is:
cmake -G "Visual Studio 17 2022" ..
As of today (October 2, 2024) I find that cmake places glfw3.lib and glfw3.pdb in build\src\Debug (Why in the source directory, I have no idea. Doesn't make sense to me).
The include file (glfw.h) will be in glfw-3.4\include\GLFW. It will NOT be in the build directory.
Now, in the redbook examples, things are a bit outdated. The source file for the triangles example (01-triangles.cpp) includes vgl.h and LoadShaders.h
LoadShaders.h has the following line in it:
#include <GL/gl.h>
You need to change this to <GL/glcorearb.h> which was generated with the gl3w python script. Never use glcorearb.h and gl.h in the same project.
You will also find the following in vgl.h:
#include <GL3/gl3.h> #include <GL3/gl3w.h>
Change this to:
#include <GL/gl3.h> #include <GL/gl3w.h>
The gl3w python script places headers in the GL directory rather than the GL3 directory.
To put this together do the following:
For Visual Studio:
Create a command line project. You will have a main function rather than WinMain. Open the cpp file containing main. Replace everything with what is in 01-triangles.cpp from the redbook.
Add gl3w.c and LoadShaders.cpp to your project. Add LoadShaders.h and vgl.h to your project
In LoadShaders.cpp, ensure to include #include <GL/gl3w.h> and not <GL3/gl3w.h>
In vgl.h ensure that to include the following:
#include <GL/glcorearb.h> #include <GL/gl3w.h>
Do not include <GL/gl.h>
Cross your fingers and click Build Solution.
It should build.
Oh, one other thing...
In the init function in your main source file you will find the following:
ShaderInfo shaders[] =
{
{ GL_VERTEX_SHADER, "media/shaders/triangles/triangles.vert" },
{ GL_FRAGMENT_SHADER, "media/shaders/triangles/triangles.frag" },
{ GL_NONE, NULL }
};
Grab triangles.vert and triangles.frag. I placed them in my project directory (not the solution directory. use the project directory) and changed this code to the following:
ShaderInfo shaders[] =
{
{ GL_VERTEX_SHADER, "triangles.vert" },
{ GL_FRAGMENT_SHADER, "triangles.frag" },
{ GL_NONE, NULL }
};
Your project will build without these files. However, without them, they won't load at runtime.
Hope this helps.
Upvotes: 0