So when you #include a header in C++, the compiler just copies the content of the header and pastes it where the #include was. I'm making a small game engine/framework and I'm including GLEW & GLFW in my Engine.h because I need things like GLFWwindow. But I get a compiler error in my Test Game 1 Project that uses the engine because since the compiler is just copying the code form engine.h and pasting it in test game 1's main.cpp, It's trying to include glew and glfw in my test game 1, which I don't want it to and I haven't linked against the glew and glfw libs in that project. How do I fix it so I can still access glew and glfw in engine.h without including them in test game 1?
Asked
Active
Viewed 76 times
0
-
1If you need them in the header, you need to include them. If you don't use them, don't include them. There's not really any other ways to do it. Without seeing any code it's impossible to say anything else – Sami Kuhmonen Oct 01 '16 at 22:40
-
Show us code so we can help you. Thanks – amanuel2 Oct 01 '16 at 22:45
-
1Rewrite your `engine.h` to [use the pimpl design pattern](http://stackoverflow.com/questions/3597693/how-does-the-pimpl-idiom-reduce-dependencies). – Sam Varshavchik Oct 01 '16 at 22:45
1 Answers
0
You have two options. 1. Either you statically link your project with glew and glfw libraries and then call GLFWwindow function 2. Or you load glew and glfw libraries in the c++ code using LoadLibrary() and then call GLFWwindow function using GetProcAddess()

Pradip Pandey
- 41
- 2