Lnk 2019 error

Feb 21, 2020 at 2:22pm
Please help
at the same proj same dir
working code
<#include "GLFW/glfw3.h"
#pragma comment(lib, "glfw3.lib")
namespace Hazel {
m_Window = glfwCreateWindow((int)props.Width, (int)props.Height, m_Data.Title.c_str(), nullptr, nullptr);
glfwMakeContextCurrent(m_Window);
glfwSetWindowUserPointer(m_Window, &m_Data);
};>

not working code

<#include "Application.h"
#include "GLFW/glfw3.h"
#pragma comment(lib, "glfw3.lib")
#include "Events/AppEvent.h"
namespace Hazel {
Application::Application()
{
m_Window =std::unique_ptr<Window> (Window::Create());
}
void Application::Run(){
while (m_Runing)
{
glClearColor(1,0,1,1);
glClear(GL_COLOR_BUFFER_BIT);
m_Window->OnUpdate();
}
}
}>
glfw3.lib is added to the AdditionalDependencies glfw3.lib
and
AdditionalLibraryDirectories " $(SolutionDir)Hazel\vendor\glfw\include\GLFW

Errors
LNK2019 unresolved external symbol __imp_glClearColor referenced in function "public: void __cdecl Hazel::Application::Run(void)"
LNK2019 unresolved external symbol __imp_glClear referenced in function "public: void __cdecl Hazel::Application::Run(void)" C:\Dev\Hazel\Hazel\Hazel\Application.obj
Last edited on Feb 22, 2020 at 4:30pm
Feb 21, 2020 at 6:11pm
Basic gl* 1.0 commands like glClearColor are provided by linking with opengl.
So you need something like "opengl.lib", or maybe it's "opengl32.lib".
Feb 23, 2020 at 12:19am
I looked for opengl libarary this is what I found so its what I am trying to do:

"There isn't a newer OpenGL library for windows, and there won't be. They decided to stop at OpenGL 1.1 and even call it a legacy graphics.
However, you can use load opengl function, and that is how people get access to the latest opengl features.
You can also use GLEW library to get access to the opengl functions.
so I didn't solve my problem yet"
thanks for your help
Feb 23, 2020 at 12:28am
you can try to compile it yourself, maybe; isn't opengl open?
I do not know if that will work, just throwing the idea out.
Feb 23, 2020 at 2:32am
Use a library like GLEW
http://glew.sourceforge.net/

Or a "library generator" like GLAD
https://glad.dav1d.de/

To handle loading a particular OpenGL profile at run-time. See
http://www.opengl-tutorial.org/beginners-tutorials/tutorial-1-opening-a-window/
For instructions about the former.
Last edited on Feb 23, 2020 at 2:33am
Feb 24, 2020 at 6:09pm
@aymanawa, hmm it seems like Visual Studio works a bit differently with linking. OpenGL is weird because Microsoft has never been a champion of support for OpenGL.
But just to clarify: OpenGL 1.0/1.1 functions are provided by linking with opengl. It's not a custom library you need to download, it should already be available whether you're using Visual Studio or MinGW.

Use GLEW or GLAD like mbozzi said, that should help with a lot of function reference issues. But you probably still need to link to opengl even with GLEW or GLAD, I assume.
In MinGW it's -lopengl32
On Visual Studio, you'd do something like:
In Visual C++ go to Project, Settings, and then click on the LINK tab. Under "Object/Library Modules" at the beginning of the line (before kernel32.lib) add OpenGL32.lib
Topic archived. No new replies allowed.