0

I am writting a game, and at the same time building an engine for it and for other games I may make in the future. During testing on both the game logic and the engine (separately) run well. However when I try to link them together, I encountered some problem with the inclusion of header files.

To be specific, here is what I did:

The engine is built as Static Library (.lib), and depends on GLFW static library (glfw3.lib). It contains a Window.h file:

// Window.h
#pragma once
#include <glfw3.h> // include other library's header

#include <iostream>
//test if the linking success
void test() {
    std::cout << "this is Window.h";
}    

class Window
{
    // Window class code (declaration, function prototype, etc...)
}

*Note that the location of GLFW library is separated from engine/game project location.

The game project is hosted under the same Solution with the engine project. In the game's Properties, I have add the engine as dependencies as well as engine's .lib and include location. Then I try the following:

// game's main file
#include <Window.h> 

void main()
{
    test(); // call the test function from Window.h
}

When building the game, I got an error says that it can not find such file called "glfw3.h". However, if I comment out the inclusion of glfw3.h in Window.h file:

# Window.h
#pragma once
//#include <glfw3.h>

then the game build and run normally, and prints out the test line in test function.

I want to build the engine as a single .lib with header files that prototypes functions for its classes; so that in the game project I only need to include/depend the engine library and no need to care about GLFW or such. How can I achive that? I found a similar question, but it seems the answers don't solve my question.

3x3y3z3t
  • 1
  • 4
  • Have you added the path to the folder containing glew.h to the project's "Additional Include Directories" property? – mayaknife Jan 01 '18 at 15:57
  • In Engine's project, I've added the path to glew.h in both "Include Directories" and "Additional Include Directories". In Game's project, I don't add anything related to GLEW or sort, since my goal is to make game depends only on engine itself. – 3x3y3z3t Jan 04 '18 at 14:46
  • Why does Window.h include glew.h? What in Window.h depends upon it? – mayaknife Jan 05 '18 at 16:29
  • I'm sorry, not glew.h but actually glfw3.h (I just include glew.h temporarily for testing). Original question edited. This time I have added the path to glfw3.h in "Additional Include Directories" as absolute path. – 3x3y3z3t Jan 06 '18 at 12:35

1 Answers1

0

You could try the suggestion from the related post below. Basically build your library as you are doing then statically merge it with the glfw static lib.

How to merge two windows vc static library into one

the4thamigo_uk
  • 835
  • 4
  • 8