Problems With GLAD and GLEW Libraries

I have a Visual Studio c++ project in which I am using GLFW.
I have seen tutorials using glad, as well as GLEW alongside GLFW.
However, I am getting errors, which I don’t know how to solve, or why I am getting them. I am following tutorials, including the ones from GLFW website.

When I use this code…

// If using GLEW version 1.13 or earlier
	//glewExperimental = true;
	GLenum err = glewInit();
	if (err != GLEW_OK) {
		// Problem: glewInit failed, something is seriously wrong.
		cout << "glewInit failed: " << glewGetErrorString(err) << endl;
		exit(1);
	}

I get these errors…

Error LNK2019 unresolved external symbol __imp_glewInit referenced in function private: bool __cdecl mainWindow::init(void) (?init@mainWindow@@AEAA_NXZ)
Error LNK2019 unresolved external symbol __imp_glewGetErrorString referenced in function private: bool __cdecl mainWindow::init(void) (?init@mainWindow@@AEAA_NXZ)
Error LNK1120 2 unresolved externals

I tried the solution [unresolved external symbol __imp__glewInit VS __imp__glewInit@0] on stackoverflow, but it does not solve the problem.

#include <GL/glew.h>
#define GLEW_STATIC
//#include <glad/glad.h>
#include "Window.h";

I’m wondering if the problem has anything to do with the architecture. I can’t find 64 bit GLEW.

I also have a problem using the glad library.
When I include glad
#include <glad/glad.h>
I get an error telling me to remove the include because it is already included.

So when I try this…
gladLoadGL([glfwGetProcAddress);
gladLoadGL is undefined, suggesting that glad is not included.

Any suggestion on how I can resolve these issues would be much appreciated. Thanks.

For the GLEW problem, this thread helped me get rid of the error.

I added glew32.lib in Linker’s Additional Libraries.
I now only need a solution to the problem with the glad library. Thanks.

You didn’t link with the GLEW library, or you linked to the wrong version of that library.

The #define comes before the include. It wouldn’t be able to affect anything otherwise.

You’ll need to provide more code than just a #include if you want us to be able to help.

Thank you.
When I include glad, like so…

#include <GL/glew.h>
#include <glad/glad.h>
#include "Window.h";

I get an error. This…

|Error|C1189|#error: OpenGL header already included, remove this include, glad already provides it||

GLEW and GLAD do the same thing. There is no reason to have a file that uses both. And the only reason to have a project that uses both is if you’re including some library that uses one while you’re using the other, but even then, you have to separate them out so that no single file tries to include both (directly or indirectly).

If this is all your code, then you need to pick which one you want to use.

What happened, is I was trying GLEW, and that failed, so I tried GLAD.
In any case, I wanted to see if I could get GLAD to work.

If the problem with GLAD cannot be resolved, I suppose I don’t need to bother with it.
Still, it would be helpful to know why it isn’t working.
Thanks.

I thought I explained that: you cannot use both GLAD and GLEW in the same file. They both try to include the OpenGL headers, and they both expect to be the only code doing that. So either of them will error in the presence of the other. Get rid of #include <GL/glew.h> (and all other vestiges of GLEW), and GLAD will work.

No, you did not explain that. Thank you.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.