Visual Studio 2010:使用多个 C++项目
我正在使用 VS2010 用 C++ 开发一个游戏引擎项目。我们有一个主要项目,OgreProject,其中包括一些用于渲染的 Ogre3D 内容。然后,我们有一个名为 AudioLibrary 的类库项目。 AudioLibrary 使用 fmod,并包含适当的标头和库。当 OgreProject 中的类想要使用 AudioLibrary 中的 SoundPlayer.h 时,就会出现问题。然后,OgreProject 不知道#include 在哪里。告诉 OgreProject fmod 在哪里感觉是错误的,因为它不会直接使用这些标头。在 OgreProject 不知道的情况下,在 OgreProject 中使用 AudioLibrary 中的头文件的正确方法是什么?
I am working on a game engine project in C++ with VS2010. We have one main project, OgreProject, which includes some Ogre3D stuff for rendering. Then, we have a class library project called AudioLibrary. AudioLibrary uses fmod, and has includes to the appropriate headers and libs. The problem arises when a class in OgreProject wants to use the SoundPlayer.h in AudioLibrary. Then, OgreProject does not know where #include is. It feels wrong to tell OgreProject where fmod is, since it will not directly use these headers. What is the correct way to using header files from AudioLibrary in OgreProject, without OgreProject knowing of ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有正确的方法。一个图书馆没有什么神奇的方法可以了解另一个图书馆;你必须配置它们才能做到这一点。如果将它们放在同一解决方案中,您可以将一个项目添加到另一个项目作为项目引用。
There is no correct way. There's no magical way for one library to know about the other library; you'd have to configure them to do that. If you put them in the same solution you can add one project to another as a project reference.
您可以尝试 Pimpl 习惯用法(或模式)。
它可以让您从项目的头文件中删除与
fmod
相关的所有内容。只有实现文件需要fmod
标头,而不是客户端项目。请参阅此答案,其中解释了好处。
You might try the Pimpl idiom (or pattern).
It will let you remove everything related to
fmod
from your project's header file. Only the implementation files will need thefmod
headers, not client projects.See this answer which explains the benefits.
您可能应该为项目的所有组件定义一个层次结构,并将来自特定组件的所有头文件保留在预定义的位置,其他组件将使用这些头文件。然后其他组件就可以随时查看这个地方。明确告诉组件在哪里寻找这些依赖项并没有什么错
You should probably define a heirarchy for all the components of your project and keep all the header files from a particular component which other components are going to use at a pre-defined place. Other components can then always look at this place. There is nothing wrong in telling the components where to look for these dependencies explicitly