好吧,我这几天一直在为此苦苦挣扎。我正在从头开始为 CryENGINE 编写自定义游戏 DLL,我什至无法使用一个简单的类 (Game.cpp) 和预编译的头文件 (StdAfx.h) 来编译解决方案。
Game.cpp 和 StdAfx.cpp 都可以自行完美编译,但编译解决方案会引发大量多重定义错误。该类很简单,因为定义只是占位符。
游戏.h
#if !defined __GAME__H__
#define __GAME__H__
#pragma once
class CGame : public IGame
{
public:
CGame();
VIRTUAL ~CGame();
//IMPLEMENT: IGame Interface, all methods declared.
};
#endif
游戏.cpp
#include "StdAfx.h" //PreComp header
#include "Game.h"
//Define all methods, each one has a simple definition.
标准Afx.h
#if !defined __STDAFX__H__
#define __STDAFX__H__
#pragma once
//Various CryENGINE includes
#endif
输出
error LNK2005: "struct SSystemGlobalEnvironment * gEnv" (? gEnv@@3PEAUSSystemGlobalEnvironment@@EA) already defined in StdAfx.obj
error LNK2005: "public: static long volatile _CryMemoryManagerPoolHelper::allocatedMemory" (?allocatedMemory@_CryMemoryManagerPoolHelper@@2JC) already defined in StdAfx.obj
error LNK2005: "public: static long volatile _CryMemoryManagerPoolHelper::freedMemory" (?freedMemory@_CryMemoryManagerPoolHelper@@2JC) already defined in StdAfx.obj
error LNK2005: "public: static long volatile _CryMemoryManagerPoolHelper::requestedMemory" (?requestedMemory@_CryMemoryManagerPoolHelper@@2JC) already defined in StdAfx.obj
error LNK2005: "public: static int volatile _CryMemoryManagerPoolHelper::numAllocations" (?numAllocations@_CryMemoryManagerPoolHelper@@2HC) already defined in StdAfx.obj
The list goes on...
真正让我失望的是,每一个都可以单独编译,所以语法和引用都很好。将解决方案作为一个整体编译时,什么可能导致多重定义的错误?
对于这个令人沮丧的问题,我非常感谢您的帮助,谢谢。