C ++:引用静态库的静态库

时间:2014-02-20 02:28:41

标签: c++ static-libraries game-engine static-linking

我正在重构一个框架,我可以使用一些建议进行设计。请考虑以下事项:

gl_utils.lib包含结构:

namespace gl_utils
{
    struct LVec2
    {
        GLfloat x;
        GLfloat y;
        LVec2() {}
        LVec2(GLfloat x, GLfloat y): x(x), y(y) {}
    };
}

但是animation_utils.lib包含一个在不同静态库中使用结构的对象:

#include "gl_utils.h"
using namespace gl_utils;

class Part
{
    public:
        LVec2 Location;
        float Rotation;
        LVec2 Scaling;
        int Index;
        int Flip;

        Part();
};

这是个坏主意吗?有没有一种安全的方法可以让库相互构建,还是有一种我可以忽略的技术?

1 个答案:

答案 0 :(得分:1)

完全没问题。您必须记录它,因为最终的可执行文件或共享库需要与两个静态库链接。

如果您不想为animation_utils引入对gl_utils的依赖,那么您可以引入一个核心库来保存LVec2(以及可能的其他类型)结构,因为它不仅仅与gl相关。

您仍然需要链接核心库,但它可以使架构更加模块化。