简体   繁体   English

依赖于其他静态库的静态库

[英]Static library that depends on other static libraries

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). 该引擎是作为静态库(.lib)构建的,并且依赖于GLFW静态库(glfw3.lib)。 It contains a Window.h file: 它包含一个Window.h文件:

// 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. *请注意,GLFW库的位置与引擎/游戏项目的位置分开。

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. 在游戏的“属性”中,我已将引擎添加为依赖项以及引擎的.lib和包含位置。 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". 制作游戏时,出现错误消息,提示找不到名为“ glfw3.h”的文件。 However, if I comment out the inclusion of glfw3.h in Window.h file: 但是,如果我注释掉Window.h文件中包含glfw3.h:

# 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; 我想用头文件将引擎构建为单个.lib,头文件为其类的函数原型化; so that in the game project I only need to include/depend the engine library and no need to care about GLFW or such. 因此在游戏项目中,我只需要包含/依赖引擎库,而无需关心GLFW等。 How can I achive that? 我该如何实现? I found a similar question , but it seems the answers don't solve my question. 我找到了类似的问题 ,但似乎答案无法解决我的问题。

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. 基本上在执行操作时构建库,然后将其与glfw静态库静态合并。

How to merge two windows vc static library into one 如何将两个Windows VC静态库合并为一个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM