gpt4 book ai didi

c++ - IrrLicht - 链接器错误,重新定义

转载 作者:行者123 更新时间:2023-11-30 04:09:04 29 4
gpt4 key购买 nike

我正在开展一个项目,在该项目中我使用了外部库 IrrLicht。我遇到的问题是我包含的外部头文件中也有定义。链接器不太喜欢这个,它提示重新定义。我应该去另一个图书馆还是这是解决这个问题的方法?哦,顺便说一句,我正在使用 vs 2010。

示例 math3.h

#ifndef MATH_H
#define MATH_H

#include "quat.h"

class Point{
public:
float x;
float y;
float z;
Point (float _x, float _y, float _z){
x=_x;
y=_y;
z=_z;
}
Point(){
x=0;
y=0;
z=0;
}
irr::core::vector3df operator-(Point p){
return irr::core::vector3df(this->x-p.x,this->y-p.y,this->z-p.z);
}
float distance(Point p){
return sqrt((this->x-p.x)*(this->x-p.x)+(this->y-p.y)*(this->y-p.y)+(this->z-p.z)*(this->z-p.z));
}
Point operator+(irr::core::vector3df v){
return Point(this->x+v.X,this->y+v.Y,this->z+v.Z);
}
};

碰撞体.h

#ifndef COLLIDABLES_H
#define COLLIDABLES_H


#include "quat.h"
#include "math3.h"


class Sphere{
public:
Point cm;
float R;
irr::core::vector3df speed;
};

四.h

#ifndef QUAT_H
#define QUAT_H

#include "irrlicht.h"

#endif

初始化项目.cpp

#include <vector>
#include <time.h>

#include "InitializeItems.h"
#include "math3.h"
#include "quat.h"
#include "collidables.h"



#define SQRT2 1.4142135;
#define DIVSQRT2 0.70710678118;



std::vector<Sphere> InitializeAtoms(int N, float R)
{

std::vector<Sphere> spheres;
spheres.reserve(N);
srand(time(NULL));
Sphere sph;
for (int i=0;i<N;i++){

sph.cm=Point(rand()%2*N*R,rand()%2*N*R,rand()%2*N*R);
sph.R=R;
sph.speed=irr::core::vector3df(rand()%10,rand()%10,rand()%10);
spheres.push_back(sph);

}
return spheres;
}
std::vector<Molecule3> InitializeMol (int N, float R){

std::vector<Molecule3> mols;
mols.reserve(N);
srand(time(NULL));
Molecule3 m;
for (int i=0;i<N;i++){

m.cm=Point(rand()%2*N*R,rand()%2*N*R,rand()%2*N*R);
m.R=R;
m.sph1=m.sph2=m.sph3=(m.cm-Point(0,0,0));
m.orientation=irr::core::quaternion(rand(),rand(),rand(),rand());
m.orientation.normalize();
m.w=AxisAngle(irr::core::vector3df(rand(),rand(),rand()),rand()%360);
m.w.v.normalize();
irr::core::vector3df temp1,temp2,temp3;
temp1=irr::core::vector3df(-R,-R,0);
temp2=irr::core::vector3df(R,-R,0);
temp3=irr::core::vector3df(0,R,0);
temp1=fromRotation(m.orientation,temp1);
temp2=fromRotation(m.orientation,temp2);
temp3=fromRotation(m.orientation,temp3);
m.sph1+=temp1;
m.sph2+=temp2;
m.sph3+=temp3;
mols.push_back(m);

}
return mols;
}

初始化项目.h

#ifndef INITIALIZEITEMS_H
#define INITIALIZEITEMS_H

#include <vector>
#include "collidables.h"


std::vector<Sphere> InitializeAtoms(int N, float R);
std::vector<Molecule3> InitializeMol(int N, float R);

#endif

链接器错误:

1>main.obj : error LNK2005: "class irr::core::quaternion __cdecl fromVector(class irr::core::vector3d<float>)" (?fromVector@@YA?AVquaternion@core@irr@@V?$vector3d@M@23@@Z) already defined in InitiliazeItems.obj
1>main.obj : error LNK2005: "class irr::core::vector3d<float> __cdecl purequatToVector(class irr::core::quaternion)" (?purequatToVector@@YA?AV?$vector3d@M@core@irr@@Vquaternion@23@@Z) already defined in InitiliazeItems.obj
1>main.obj : error LNK2005: "class irr::core::vector3d<float> __cdecl fromRotation(class irr::core::quaternion,class irr::core::vector3d<float>)" (?fromRotation@@YA?AV?$vector3d@M@core@irr@@Vquaternion@23@V123@@Z) already defined in InitiliazeItems.obj
1>physics.obj : error LNK2005: "class irr::core::quaternion __cdecl fromVector(class irr::core::vector3d<float>)" (?fromVector@@YA?AVquaternion@core@irr@@V?$vector3d@M@23@@Z) already defined in InitiliazeItems.obj
1>physics.obj : error LNK2005: "class irr::core::vector3d<float> __cdecl purequatToVector(class irr::core::quaternion)" (?purequatToVector@@YA?AV?$vector3d@M@core@irr@@Vquaternion@23@@Z) already defined in InitiliazeItems.obj
1>physics.obj : error LNK2005: "class irr::core::vector3d<float> __cdecl fromRotation(class irr::core::quaternion,class irr::core::vector3d<float>)" (?fromRotation@@YA?AV?$vector3d@M@core@irr@@Vquaternion@23@V123@@Z) already defined in InitiliazeItems.obj
1>visuals.obj : error LNK2005: "class irr::core::quaternion __cdecl fromVector(class irr::core::vector3d<float>)" (?fromVector@@YA?AVquaternion@core@irr@@V?$vector3d@M@23@@Z) already defined in InitiliazeItems.obj
1>visuals.obj : error LNK2005: "class irr::core::vector3d<float> __cdecl purequatToVector(class irr::core::quaternion)" (?purequatToVector@@YA?AV?$vector3d@M@core@irr@@Vquaternion@23@@Z) already defined in InitiliazeItems.obj
1>visuals.obj : error LNK2005: "class irr::core::vector3d<float> __cdecl fromRotation(class irr::core::quaternion,class irr::core::vector3d<float>)" (?fromRotation@@YA?AV?$vector3d@M@core@irr@@Vquaternion@23@V123@@Z) already defined in InitiliazeItems.obj

编辑:添加链接器错误

edit2:链接到整个项目的github https://github.com/DxsGeorge/Collider

最佳答案

似乎“已经定义”的问题来自其他三个类(主要、物理、视觉),所以显示更多关于它们的信息,无论如何我建议你不要使用

#ifndef
#define

#endif

使用

#pragma once

在头文件的开头,这将做同样的事情(仅在 visual studio 上)并且不容易出错。

关于c++ - IrrLicht - 链接器错误,重新定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21515551/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com