multiply defined error

Hi
When I compile my project I’m getting this errors.

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

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))
    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");
}

when I remove this line its working.

if (!PxInitExtensions(*m_Physics))
printf(“PxInitExtensions failed!\n”);

what is the problem?

Hi,

I guess you dont use a header guard.
Most “already defined in …” happens due to forgotten header guards.
( Or double linked libraries)

Just try to use “#pragma once” in all your header files.
( Or better: Use a precompiled header, which includes all header which dont change often to
save huge time while compiling other files ← but you have to include everywhere the header to the
precompiled header file. Just google for it )

This should be an common linking error - its nothing PhysX specific, I think.

I’m using #pragma once in all of my header files.It seems one of physx files forgot to use it.But I managed to solve this problem by including physx directly as the first header of my project.I don’t know how but its working now. :)

Hi.

Of course, I forgot this way :)
Good that you found the solution to it :)