<函数列表>的多重定义

Multiple definition of <List of functions>

本文关键字:定义 列表 lt 函数 gt      更新时间:2023-10-16

我敢肯定答案正直勾勾地盯着我,但我因此无法取得任何进展......首先是一些代码:

objects/testObject.h:

#include <irrlicht.h>
#include "../maths.h"
using namespace irr;
#ifndef testObject_H
#define testObject_H
class testObject : public scene::SAnimatedMesh
{
    public:
        testObject(IrrlichtDevice* device);
        virtual ~testObject();
    protected:
        const char* meshInfoLocation;
        int totAnims;
    private:
};
#endif

objects/testObject.cpp:

#include "testObject.h"
testObject::testObject(IrrlichtDevice* device) : scene::SAnimatedMesh()
{
    io::IrrXMLReader* modelInformation = io::createIrrXMLReader(meshInfoLocation);
    while(modelInformation->read())
    {
        if(modelInformation->getNodeName() == "totAnims") totAnims = stringToInt(modelInformation->getAttributeValue("totAnims"));
    }
}
testObject::~testObject() { } //Incomplete, but should still compile...

编译此代码时,出现以下错误:

/home/david/workspace/spaceSim/objects/testObject.cpp||In constructor ‘testObject::testObject(irr::IrrlichtDevice*)’:|
/home/david/workspace/spaceSim/objects/testObject.cpp|20|warning: comparison with string literal results in unspecified behaviour [-Waddress]|
/home/david/workspace/spaceSim/main.cpp||In function ‘int main(int, char**)’:|
/home/david/workspace/spaceSim/main.cpp|24|warning: ‘virtual bool irr::io::IFileSystem::addZipFileArchive(const c8*, bool, bool)’ is deprecated (declared at /home/david/irrlicht-1.8.1/include/IFileSystem.h:228) [-Wdeprecated-declarations]|
/home/david/workspace/spaceSim/objects/testObject.cpp||In constructor ‘testObject::testObject(irr::IrrlichtDevice*)’:|
/home/david/workspace/spaceSim/objects/testObject.cpp|20|warning: comparison with string literal results in unspecified behaviour [-Waddress]|
obj/Debug/objects/testObject.o||In function `testObject::testObject(irr::IrrlichtDevice*)':|
/home/david/workspace/spaceSim/objects/testObject.cpp|3|multiple definition of `testObject::testObject(irr::IrrlichtDevice*)'|
obj/Debug/main.o:/home/david/workspace/spaceSim/objects/testObject.cpp|3|first defined here|
obj/Debug/objects/testObject.o||In function `testObject::testObject(irr::IrrlichtDevice*)':|
/home/david/workspace/spaceSim/objects/testObject.cpp|3|multiple definition of `testObject::testObject(irr::IrrlichtDevice*)'|
obj/Debug/main.o:/home/david/workspace/spaceSim/objects/testObject.cpp|3|first defined here|
obj/Debug/objects/testObject.o||In function `testObject::~testObject()':|
/home/david/workspace/spaceSim/objects/testObject.cpp|27|multiple definition of `testObject::~testObject()'|
obj/Debug/main.o:/home/david/workspace/spaceSim/objects/testObject.cpp|27|first defined here|
obj/Debug/objects/testObject.o||In function `testObject::~testObject()':|
/home/david/workspace/spaceSim/objects/testObject.cpp|27|multiple definition of `testObject::~testObject()'|
obj/Debug/main.o:/home/david/workspace/spaceSim/objects/testObject.cpp|27|first defined here|
obj/Debug/objects/testObject.o||In function `virtual thunk to testObject::~testObject()':|
/home/david/workspace/spaceSim/objects/testObject.cpp|29|multiple definition of `virtual thunk to testObject::~testObject()'|
obj/Debug/main.o:/home/david/workspace/spaceSim/objects/testObject.cpp|29|first defined here|
obj/Debug/objects/testObject.o||In function `testObject::~testObject()':|
/home/david/workspace/spaceSim/objects/testObject.cpp|27|multiple definition of `testObject::~testObject()'|
obj/Debug/main.o:/home/david/workspace/spaceSim/objects/testObject.cpp|27|first defined here|
obj/Debug/objects/testObject.o||In function `virtual thunk to testObject::~testObject()':|
/home/david/workspace/spaceSim/objects/testObject.cpp|29|multiple definition of `virtual thunk to testObject::~testObject()'|
obj/Debug/main.o:/home/david/workspace/spaceSim/objects/testObject.cpp|29|first defined here|
||=== Build finished: 14 errors, 3 warnings ===|

我已经尝试了以下解决方法:

  • 合并标头和 cpp 文件。
  • 清空所有方法主体并删除 #includes 以便所有重要的是类结构。
  • 谷歌搜索(没有任何运气...

谢谢你的帮助!

我使用 mingw32 (www.mingw.org) 中的 gcc4.8.1 编译了您的代码(将它们放入文件中,并替换缺少的类型)。编译似乎还可以。我想问题可能是

#include <irrlicht.h>
#include "../maths.h"

法典:

//#include <irrlicht.h>
//#include "../maths.h"
//using namespace irr;
#ifndef testObject_H
#define testObject_H
#include <tuple>
namespace scene {
  typedef  std::tuple<int,int> SAnimatedMesh;
};
typedef int IrrlichtDevice;
class testObject : public scene::SAnimatedMesh
{
    public:
        testObject(IrrlichtDevice* device);
        virtual ~testObject();
    protected:
        const char* meshInfoLocation;
        int totAnims;
    private:
};
#endif
//#include "testObject.h"
testObject::testObject(IrrlichtDevice* device) : scene::SAnimatedMesh()
{
  /*
    io::IrrXMLReader* modelInformation = io::createIrrXMLReader(meshInfoLocation);
    while(modelInformation->read())
    {
        if(modelInformation->getNodeName() == "totAnims") totAnims = stringToInt(modelInformation->getAttributeValue("totAnims"));
    }
  */
}
testObject::~testObject() { } //Incomplete, but should still compile...
int main() {}