Ishan Chaudhari
Ishan Chaudhari

Reputation: 31

Linking C++ Multiple Projects in my Game Engine

So this is what happens:

I have a Project A , which contains the all source and header files for GLFW, Next I have Project B, which is my Game Engine, where I write my Code.

Then there's a Project C, which is a Sandbox Application where I test out my Engine.

Now Project A and B are Static Libs and C is a Console App. The static Lib for project A is linked in B and then B is linked to C.

Now everything compiles and builds successfully but, when I run Project C, it says that it can't find the header file from project A that I included in my Project B. The Projects A & B both build successfully by the way without errors. And yes, all include directory paths, etc are 100% Correct.

Now I did find a way around this: If I include the path for the Project A header files in Project C, It runs successfully. But I'm not sure why this happens. Could anyone explain this to me?

I'm Using Premake to Manage my Solution Files for VS 2022.

Upvotes: 2

Views: 84

Answers (1)

Silvio Mayolo
Silvio Mayolo

Reputation: 70307

Static libraries don't include header files. In fact, nothing does. Header files are solely there to inform C++ about the functions that are in the static library. In fact, the header files for Project B aren't even in the static library for Project B. When you #include <thing_from_project_b.h>, you're including the source header file from your project folder, not something from a static library.

The solution you've come up with is correct. Link the static libraries to get the correct runtime behavior however you like, and then directly tell your C++ compiler where to find all of the .h files for both projects. The static libraries you generate don't know or care about your headers.

Upvotes: 1

Related Questions