我在库(alibrary.lib)中有一个头文件。该库是一个静态库 (.lib),它正确链接到 exe。
现在,我有一个类:Vector3d。
class Vector3d
{
void amethod()
{
blah
}
};
Vector3d cross(const Vector3d &v0, const Vector3d &v1)
{
float x,y,z;
x = v0.y*v1.z-v0.z*v1.y;
y = v0.z*v1.x-v0.x*v1.z;
z = v0.x*v1.y-v0.y*v1.x;
return Vector3d(x,y,z);
}
Vector3d 在头文件 (Vector3d .h) 中声明和定义。在类声明之后,我使用了交叉函数。
lib compile 是文件,但是当它链接到单元测试 exe 时,我收到此错误:
flywindow.obj :error LNK2005: "class Vector3d __cdecl cross(class Vector3d const &,class Vector3d const &)" (?cross@@YA?AVVector3d@@ABV1@0@Z) already defined in fly.obj
有任何想法吗?
谢谢