如何在头中包含依赖项,而不将其包含在包含头的项目中 [英] How to include a dependency in a header without including it in projects that include the header

查看:128
本文介绍了如何在头中包含依赖项,而不将其包含在包含头的项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,当你在C ++中包含头文件时,编译器只是复制头文件的内容并将其粘贴到#include所在的位置。我正在制作一个小型游戏引擎/框架,并且包括GLEW& GLFW在我的Engine.h中,因为我需要像GLFWwindow这样的东西。但是我在使用引擎的测试游戏1项目中遇到了一个编译器错误,因为编译器只是复制代码形式engine.h并粘贴到测试游戏1的main.cpp中,它试图在我的测试中包含glew和glfw游戏1,我不希望它,我没有链接该项目中的glew和glfw库。如何修复它,以便我仍然可以访问engine.h中的glew和glfw,而不将它们包含在测试游戏1中?

解决方案

你有两个选择。
1.您可以使用glew和glfw库静态链接项目,然后调用GLFWwindow函数
2.或者使用LoadLibrary()在c ++代码中加载glew和glfw库,然后使用GetProcAddess调用GLFWwindow函数()


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?

解决方案

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()

这篇关于如何在头中包含依赖项,而不将其包含在包含头的项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆