Hi
I want to add physx to my engine but I'm getting a very strange errors:
1>------ Build started: Project: Game, Configuration: Debug Win32 ------
1>PhysX3CommonCHECKED_x86.lib(PhysX3CommonCHECKED_x86.dll) : error LNK2005: "public: class physx::PxFlags<enum physx::PxSerialFlag::Enum,unsigned short> __thiscall physx::PxFlags<enum physx::PxSerialFlag::Enum,unsigned short>::operator~(void)const " (??S?$PxFlags@W4Enum@PxSerialFlag@physx@@G@physx@@QBE?AV01@XZ) already defined in FreeCamera.obj
1>PhysX3CommonCHECKED_x86.lib(PhysX3CommonCHECKED_x86.dll) : error LNK2005: "public: __thiscall physx::PxFlags<enum physx::PxSerialFlag::Enum,unsigned short>::PxFlags<enum physx::PxSerialFlag::Enum,unsigned short>(enum physx::PxSerialFlag::Enum)" (??0?$PxFlags@W4Enum@PxSerialFlag@physx@@G@physx@@QAE@W4Enum@PxSerialFlag@1@@Z) already defined in FreeCamera.obj
1>PhysX3CommonCHECKED_x86.lib(PhysX3CommonCHECKED_x86.dll) : error LNK2005: "public: class physx::PxFlags<enum physx::PxSerialFlag::Enum,unsigned short> & __thiscall physx::PxFlags<enum physx::PxSerialFlag::Enum,unsigned short>::operator&=(class physx::PxFlags<enum physx::PxSerialFlag::Enum,unsigned short> const &)" (??_4?$PxFlags@W4Enum@PxSerialFlag@physx@@G@physx@@QAEAAV01@ABV01@@Z) already defined in FreeCamera.obj
1>PhysX3CommonCHECKED_x86.lib(PhysX3CommonCHECKED_x86.dll) : error LNK2005: "public: __thiscall physx::PxFlags<enum physx::PxSerialFlag::Enum,unsigned short>::PxFlags<enum physx::PxSerialFlag::Enum,unsigned short>(void)" (??0?$PxFlags@W4Enum@PxSerialFlag@physx@@G@physx@@QAE@XZ) already defined in FreeCamera.obj
1>PhysX3CommonCHECKED_x86.lib(PhysX3CommonCHECKED_x86.dll) : error LNK2005: "public: __thiscall physx::PxFlags<enum physx::PxSerialFlag::Enum,unsigned short>::PxFlags<enum physx::PxSerialFlag::Enum,unsigned short>(class physx::PxFlags<enum physx::PxSerialFlag::Enum,unsigned short> const &)" (??0?$PxFlags@W4Enum@PxSerialFlag@physx@@G@physx@@QAE@ABV01@@Z) already defined in FreeCamera.obj
1>PhysX3CommonCHECKED_x86.lib(PhysX3CommonCHECKED_x86.dll) : error LNK2005: "public: __thiscall physx::PxFlags<enum physx::PxSerialFlag::Enum,unsigned short>::operator bool(void)const " (??B?$PxFlags@W4Enum@PxSerialFlag@physx@@G@physx@@QBE_NXZ) already defined in FreeCamera.obj
1>PhysX3CommonCHECKED_x86.lib(PhysX3CommonCHECKED_x86.dll) : error LNK2005: "public: class physx::PxFlags<enum physx::PxSerialFlag::Enum,unsigned short> __thiscall physx::PxFlags<enum physx::PxSerialFlag::Enum,unsigned short>::operator&(enum physx::PxSerialFlag::Enum)const " (??I?$PxFlags@W4Enum@PxSerialFlag@physx@@G@physx@@QBE?AV01@W4Enum@PxSerialFlag@1@@Z) already defined in FreeCamera.obj
1>E:\Tools\game_engine\MyEngine\Engine\Debug\Game.exe : fatal error LNK1169: one or more multiply defined symbols found
I found a single line in my code that cause these errors but the code is true here my code for starting physx:
CPhysxPhysic::CPhysxPhysic(void)
{
m_Physics=NULL;
m_Foundation=NULL;
//static PxDefaultErrorCallback gDefaultErrorCallback;
//static PxDefaultAllocator gDefaultAllocatorCallback;
printf("initializing PhysX\n");
printf("creating Foundation\n");
// create foundation object with default error and allocator callbacks.
m_Foundation = PxCreateFoundation(PX_PHYSICS_VERSION,gDefaultAllocatorCallback,gDefaultErrorCallback);
printf("creating Physics\n");
// create Physics object with the created foundation and with a 'default' scale tolerance.
m_Physics = PxCreatePhysics(PX_PHYSICS_VERSION,*m_Foundation,PxTolerancesScale());
m_Cooking = PxCreateCooking(PX_PHYSICS_VERSION, *m_Foundation, PxCookingParams());
if (!m_Cooking)
printf("PxCreateCooking failed!\n");
if (!PxInitExtensions(*m_Physics))//This line is the problem!!!
printf("PxInitExtensions failed!\n");
m_ProfileZoneManager = &PxProfileZoneManager::createProfileZoneManager(m_Foundation);
if(!m_ProfileZoneManager)
printf("PxProfileZoneManager::createProfileZoneManager failed!\n");
#ifdef PX_WINDOWS
pxtask::CudaContextManagerDesc cudaContextManagerDesc;
m_CudaContextManager = pxtask::createCudaContextManager(*m_Foundation, cudaContextManagerDesc, m_ProfileZoneManager);
if( m_CudaContextManager )
{
if( !m_CudaContextManager->contextIsValid() )
{
m_CudaContextManager->release();
m_CudaContextManager = NULL;
}
}
#endif
PxInitVehicleSDK(*m_Physics);
PxVehicleSetBasisVectors(PxVec3(0,1,0),PxVec3(0,0,1));
// static PxDefaultSimulationFilterShader gDefaultFilterShader;
PxSceneDesc sceneDesc(m_Physics->getTolerancesScale());
sceneDesc.gravity = PxVec3(0.0f, -9.81f, 0.0f);
// customizeSceneDesc(sceneDesc);
if(!sceneDesc.cpuDispatcher)
{
m_CpuDispatcher = PxDefaultCpuDispatcherCreate(2);
if(!m_CpuDispatcher)
printf("PxDefaultCpuDispatcherCreate failed!\n");
sceneDesc.cpuDispatcher = m_CpuDispatcher;
}
if(!sceneDesc.filterShader)
sceneDesc.filterShader = PxDefaultSimulationFilterShader;
#ifdef PX_WINDOWS
if(!sceneDesc.gpuDispatcher && m_CudaContextManager)
{
sceneDesc.gpuDispatcher = m_CudaContextManager->getGpuDispatcher();
}
#endif
m_Scene = m_Physics->createScene(sceneDesc);
if (!m_Scene)
printf("createScene failed!\n");
printf("PhysX initialized\n");
}
If I remove this line I an compile the code:
if (!PxInitExtensions(*m_Physics))//This line is the problem!!!
printf("PxInitExtensions failed!\n");
Why I got multiply defined symbols?and how should I solve it?
EDIT:I solve it my self(after 3 days of testing I finally found the answer 5 minutes after asking here :D).I included <PxPhysicsAPI.h> before any other header file and it solved my problem.