简体   繁体   English

我应该按什么顺序来构建C ++静态库

[英]What order should I build my C++ static libraries

I have 3 static libraries graphics.lib, graphics_opengl.lib and graphics_d3d.lib 我有3个静态库graphics.lib,graphics_opengl.lib和graphics_d3d.lib

from graphics.lib: 来自graphics.lib:

class DeviceInfo
{
   public:
    std::string name;
};

class GenericGraphicDevice
{
  public:
    // example function populating info_out with generic device information.
    virtual void GetDeviceinfo( DeviceInfo &info_out ); 

    //...
};

from graphics_opengl.lib: 来自graphics_opengl.lib:

class OpenGLDeviceInfo : public DeviceInfo
{
   public:
    int gl_version;
};

class OpenGLGraphicDevice : public GenericGraphicDevice
{
  public:
    // example function populating info_out with gl specific device info and
    // probably calling the base function it overrides to pick up the generic data.
    virtual void GetDeviceInfo( DeviceInfo &info_out );

    //...
};

The same setup as above for the graphics_d3d.lib. 与上述graphics_d3d.lib相同的设置。

So I have 4 projects open in my Visual studio solution. 因此,我在Visual Studio解决方案中有4个项目处于打开状态。 1 for the game, then 1 for each library. 1个游戏,然后每个库1个。

Option 1) I reference the d3d and opengl projects in the generic graphics project so my build order is: 选项1)我在通用图形项目中引用了d3d和opengl项目,因此我的构建顺序是:

d3d OR opengl
Then graphics

Option 2) d3d and opengl reference the generic graphics, so my build order is: 选项2)d3d和opengl引用了通用图形,因此我的构建顺序是:

graphics
d3d OR opengl

To my way of thinking d3d and opengl inherit objects from graphics, so how can they compile/link correctly when graphics hasn't been built yet? 以我的思维方式,d3d和opengl从图形继承对象,那么当尚未构建图形时,它们如何正确编译/链接?

Therefore I have been creating local builds using Option 2 for a while now, but recently discovered other devs have been using Option 1. 因此,我已经使用Option 2创建本地构建已有一段时间了,但是最近发现其他开发人员一直在使用Option 1。

Any clarification whether my thinking is right or wrong here and why, would be greatly appreciated. 任何澄清我的想法是对还是错以及为什么的任何澄清,将不胜感激。

If they are all static libraries, there should be no dependencies among them. 如果它们都是静态库,则它们之间应该没有依赖关系。 In other words, they are all independent. 换句话说,它们都是独立的。 This way, they can build in parallel. 这样,它们可以并行构建。

The "game" project should be dependent on all three of the static libraries so it will be built after all of the libraries are built. “游戏”项目应依赖于所有三个静态库,因此将在构建所有库之后构建它。

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

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