我在我创建的头文件(MapData.h)中定义了命名空间“MAPDATA”,并在“MAPDATA”中定义了一个变量。
地图数据.h
namespace MAPDATA{
cocos2d::CCSize MapSizeData;
cocos2d::CCSize TileSizeData;
int MaxTileXData;
int MaxTileYData;
}
但是,如果我在 else 类中写 #include "MapData.h",Linker 会出现以下错误。
duplicate symbol __ZN7MAPDATA11MapSizeDataE in:
/Users/nyoronyoro-kun/Desktop/出力先/Build/Intermediates/tilegame.build/Debug-iphonesimulator/tilegame.build/Objects-normal/i386/TileMapManage.o
/Users/nyoronyoro-kun/Desktop/出力先/Build/Intermediates/tilegame.build/Debug-iphonesimulator/tilegame.build/Objects-normal/i386/MapData.o
duplicate symbol __ZN7MAPDATA12TileSizeDataE in:
/Users/nyoronyoro-kun/Desktop/出力先/Build/Intermediates/tilegame.build/Debug-iphonesimulator/tilegame.build/Objects-normal/i386/TileMapManage.o
/Users/nyoronyoro-kun/Desktop/出力先/Build/Intermediates/tilegame.build/Debug-iphonesimulator/tilegame.build/Objects-normal/i386/MapData.o
duplicate symbol __ZN7MAPDATA12MaxTileXDataE in:
/Users/nyoronyoro-kun/Desktop/出力先/Build/Intermediates/tilegame.build/Debug-iphonesimulator/tilegame.build/Objects-normal/i386/TileMapManage.o
/Users/nyoronyoro-kun/Desktop/出力先/Build/Intermediates/tilegame.build/Debug-iphonesimulator/tilegame.build/Objects-normal/i386/MapData.o
duplicate symbol __ZN7MAPDATA12MaxTileYDataE in:
/Users/nyoronyoro-kun/Desktop/出力先/Build/Intermediates/tilegame.build/Debug-iphonesimulator/tilegame.build/Objects-normal/i386/TileMapManage.o
/Users/nyoronyoro-kun/Desktop/出力先/Build/Intermediates/tilegame.build/Debug-iphonesimulator/tilegame.build/Objects-normal/i386/MapData.o
ld: 4 duplicate symbols for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
但是,如果我删除名称空间的名称(MAPDATA)并在其他类中写入#include“MapData.h”,错误就会消失。
删除命名空间名称后
namespace {
cocos2d::CCSize MapSizeData;
cocos2d::CCSize TileSizeData;
int MaxTileXData;
int MaxTileYData;
}
如果有人能清楚地解释为什么错误消失了,我将永远感激不尽。