Search code examples
c++inheritancecompilationmsbuild

What order should I build my C++ static libraries


I have 3 static libraries graphics.lib, graphics_opengl.lib and graphics_d3d.lib

from 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:

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.

So I have 4 projects open in my Visual studio solution. 1 for the game, then 1 for each library.

Option 1) I reference the d3d and opengl projects in the generic graphics project so my build order is:

d3d OR opengl
Then graphics

Option 2) d3d and opengl reference the generic graphics, so my build order is:

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?

Therefore I have been creating local builds using Option 2 for a while now, but recently discovered other devs have been using Option 1.

Any clarification whether my thinking is right or wrong here and why, would be greatly appreciated.


Solution

  • 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.