[英]C++: Static libraries referencing Static Libraries
I am in the process of refactoring a framework, and I could use some advise for design. 我正在重构框架,可以使用一些建议进行设计。 Consider the following:
考虑以下:
gl_utils.lib contains the struct: gl_utils.lib包含以下结构:
namespace gl_utils
{
struct LVec2
{
GLfloat x;
GLfloat y;
LVec2() {}
LVec2(GLfloat x, GLfloat y): x(x), y(y) {}
};
}
however animation_utils.lib contains an object using a struct in a different static library: 但是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();
};
Is this a bad idea? 这是一个坏主意吗? Is there a safe way to have libraries build on each other, or is there a technique that I am overlooking?
有没有安全的方法可以使库彼此建立,还是有我忽略的技术?
It is perfectly fine. 很好。 You have to document it however since final executable or shared library will need to link with both static libraries.
但是,您必须对其进行记录,因为最终的可执行文件或共享库将需要与两个静态库链接。
If you don't want to introduce a dependency on gl_utils for animation_utils, you could introduce a core library for example to hold the LVec2(and possibly other types) struct as it is not exclusively gl related. 如果您不想为animation_utils引入对gl_utils的依赖关系,则可以引入一个核心库来保存LVec2(以及其他类型)结构,因为它并不与gl有关。
You'll still need to link on core library though but it could make the architecture even more modular. 尽管您仍然需要在核心库上进行链接,但这可能会使体系结构更加模块化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.