I'm trying to create a game engine. So far, I just wanted to test if my window creation program worked. I got an error:
LNK2019 unknown external symbol __imp_glewInit called in function "public: __cdecl window::window(int,int,char const*)"
I work with Visual Studio 2019 and I added additional include directory with glew library. What's more interesting, the problem occurs in function, that is defined in file with path myproject/classes/window.cpp, where myproject is my project directory. I have files directly inside the myproject directory and when i use glew in them, everything works alright. Here's my code: window.h
#pragma once
class window
{
public:
GLFWwindow* wnd;
window(int width, int height, const char* title);
void close();
};
window.cpp
#include "pch.h"
#include "..\headers.h"
#include "window.h"
window::window(int width, int height, const char* title)
{
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_COMPAT_PROFILE, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
wnd = glfwCreateWindow(width, height, title, NULL, NULL);
if (wnd == NULL) { glfwTerminate(); return; }
glfwMakeContextCurrent(wnd);
if (glewInit() != GLEW_OK) {
glfwTerminate();
return;
}
}
void window::close() {
glfwDestroyWindow(this->wnd);
}
Also, there is no "pch.h" file in myproject/classes directory. When i try "..\pch.h", Visual Studio gives me an error.
Am I doing something wrong? Should I somehow tell VS to do something with the classes directory?
PS headers.h file is in the root directory and contains
#pragma once
#include <GL/glew.h>
#include <GLFW/glfw3.h>
I tried to put above two lines into the window.cpp file, but it didn't work as well - I got exactly the same error.
Directory tree:
Pancake2d
|
|-classes
|--window.cpp
|--window.h
|-core (empty so far)
|-Debug (traditional vs debug directory)
|-lib (glew, glfw, glm here, all linked to project with vs)
|-dllmain.cpp
|-framework.h
|-headers.h
|-opengl.dll
|-pancake2d.cpp
|-pancake2d.h
|-Pancake2d.vcxproj
|-Pancake2d.vcxproj.filters
|-Pancake2d.vcxproj.user
|-pch.cpp
|-pch.h
Update:
Rrright... So... the problem is no more. I did nothing and it worked. All I did was I just added line glewInit()
in pancake2d.cpp. I got a warning, that I'm declaring a function glewInit, and import it in classes/window.cpp, so I changed the line to if (glewInit() != GLEW_OK) return false;
, which is basically the same line I used in "classes/window.cpp". I compiled - no errors, no warnings. I comment the line and compile - no errors, no warnings. I delete the line and compile - no errors, no warnings.
Update 2: The problem seemed to be not putting the glew dependency in linker. Seems like I have added header files to additional folders for include, but I was missing Linker settings.