Problem with PxDefaultErrorCallback (PhysX 3.4)

Hi everyone !

I have a problem when initializing physX (3.4). When I try to create an error callback (PxDefaultErrorCallback), I get this error :

LNK2019 unresolved external symbol “public: __thiscall physx::PxDefaultErrorCallback::PxDefaultErrorCallback(void)”

Here is my code :

PhysX.h :

#ifndef _PHYSX_
#define _PHYSX_

#include "Vec3.h"

#include "PxPhysicsAPI.h"
#include "PxDefaultAllocator.h"
#include "PxDefaultErrorCallback.h"

namespace physics
{
	class PhysX
	{
	private:
		physx::PxPhysics* _sdk = NULL;
		physx::PxFoundation* _foundation = NULL;

		physx::PxScene* _scene;

	public:
		PhysX() = default;
		~PhysX() = default;

		bool Initialize();
		void Shutdown();
	};
}

#endif

PhysX.cpp :

#include "PhysX.h"
#include <iostream>

using namespace physx;
using namespace physics;

bool PhysX::Initialize()
{
	static PxDefaultErrorCallback errorCallback; // the error appears because of this line
	static PxDefaultAllocator allocatorCallback;

	_foundation = PxCreateFoundation(PX_FOUNDATION_VERSION, allocatorCallback, errorCallback);
	if (!_foundation)
		return false;

	return true;
}

void PhysX::Shutdown(){}

I linked the minimum libraries needed (PhysX3DEBUG_x86.lib, PhysX3CommonDEBUG_x86.lib and PxFoundationDEBUG_x86.lib, I try to compile in Debug x86 for the moment). Maybe I forgot to link a library ?

I also read that I was supposed to implement the virtual function reportError in PxDefaultErrorCallback, but I just got more errors :

#ifndef PX_PHYSICS_EXTENSIONS_DEFAULT_ERROR_CALLBACK_H
#define PX_PHYSICS_EXTENSIONS_DEFAULT_ERROR_CALLBACK_H

#include "foundation/PxErrorCallback.h"
#include "PxPhysXConfig.h"

#if !PX_DOXYGEN
namespace physx
{
#endif

	/**
	\brief default implementation of the error callback

	This class is provided in order to enable the SDK to be started with the minimum of user code. Typically an application
	will use its own error callback, and log the error to file or otherwise make it visible. Warnings and error messages from
	the SDK are usually indicative that changes are required in order for PhysX to function correctly, and should not be ignored.
	*/

	class PxDefaultErrorCallback : public PxErrorCallback
	{
	public:
		PxDefaultErrorCallback();
		~PxDefaultErrorCallback();

		virtual void reportError(PxErrorCode::Enum code, const char* message, const char* file, int line); // supposed to implement that function
	};

// Code that I tried to add
/*void PxDefaultErrorCallback::reportError(PxErrorCode::Enum code, const char* message, const char* file, int line)
{
...
}*/

#if !PX_DOXYGEN
} // namespace physx
#endif

#endif

Any idea ? I don’t really see where this error could come from…

Hi,
you need to link also the extensions library, if you use the PxDefaultErrorCallback. The implementation is in this library.
So try to add a PhysX3ExtensionsDEBUG.lib to your project.

Regards,
Ales

Thanks, it was that ! The weird thing is that compiling PhysX.sln didn’t build PhysX3Extensions.lib and a few other libraries, so I had to modify the build settings, something like that…

Thanks !