Linker error by PxDefaultErrorCallback

Hello,

I am getting the linker error

Error 3 error LNK2019: unresolved external symbol “public: virtual __thiscall physx::PxDefaultErrorCallback::~PxDefaultErrorCallback(void)” (??1PxDefaultErrorCallback@physx@@UAE@XZ) referenced in function “void __cdecl `dynamic atexit destructor for ‘gDefaultErrorCallback’’(void)” (??__FgDefaultErrorCallback@@YAXXZ) C:\karemus2\physx2\physx2\Source1.obj

I do not why, because I have linked every available library:

Source code:

#include <iostream>

#include <pxphysicsapi.h>
#include <pxdefaulterrorcallback.h>
#include <pxdefaultallocator.h>

#include <Windows.h>

#pragma comment(lib, "PhysX3_x86.lib")
#pragma comment(lib,"PhysX3Common_x86.lib")

#pragma comment(lib, "PhysX3CharacterKinematic_x86.lib")
#pragma comment(lib, "PhysX3CharacterKinematicCHECKED_x86.lib")
#pragma comment(lib, "PhysX3CharacterKinematicPROFILE_x86.lib")
#pragma comment(lib, "PhysX3PROFILE_x86.lib")
//#pragma comment(lib, "PhysX3ExtensionsPROFILE.lib")
#pragma comment(lib, "PhysX3CHECKED_x86.lib")
//#pragma comment(lib, "PhysX3Extensions.lib")
//#pragma comment(lib, "PhysX3ExtensionsCHECKED.lib")
#pragma comment(lib, "PhysX3CookingPROFILE_x86.lib")
#pragma comment(lib, "PhysX3CookingCHECKED_x86.lib")
#pragma comment(lib, "physx3common_x86.lib")
#pragma comment(lib, "physx3cooking_x86.lib")
#pragma comment(lib, "physx3commonprofile_x86.lib")
#pragma comment(lib, "physx3commonchecked_x86.lib")
#pragma comment(lib, "physx3vehicle.lib")
#pragma comment(lib, "pxtask.lib")
#pragma comment(lib, "physx3vehiclechecked.lib")
#pragma comment(lib, "pxtaskchecked.lib")
#pragma comment(lib, "physx3vehicleprofile.lib")
#pragma comment(lib, "physxvisualdebuggersdkprofile.lib")
//#pragma comment(lib, "physxprofilesdk.lib")
//#pragma comment(lib, "physxprofilesdkchecked.lib")
#pragma comment(lib, "physxvisualdebuggersdkchecked.lib")
#pragma comment(lib, "physxvisualdebuggersdk.lib")
#pragma comment(lib, "pxtaskprofile.lib")
//#pragma comment(lib, "physxprofilesdkprofile.lib")
#pragma comment(lib, "pxtoolkitdebug.lib")
#pragma comment(lib, "repx3.lib")
#pragma comment(lib, "repx3checked.lib")
#pragma comment(lib, "repx3profile.lib")
#pragma comment(lib, "repxupgrader3.lib")
#pragma comment(lib, "repxupgrader3checked.lib")
#pragma comment(lib, "samplesdebug.lib")
#pragma comment(lib, "sampleplatform-mtdebug.lib")
#pragma comment(lib, "samplerenderer-mtdebug.lib")
#pragma comment(lib, "repxupgrader3profile.lib")
#pragma comment(lib, "samplebasedebug.lib")
#pragma comment(lib, "sampleframework-mtdebug.lib")
using namespace std;
using namespace physx;

//#pragma comment(lib, "Foundation")
//#pragma comment(lib, "PhysX3Extensions.lib")

const int WINDOW_WIDTH=1024,
  WINDOW_HEIGHT=768;
void InitializePhysX();
void ShutdownPhysX();

static PxPhysics* gPhysicsSDK = NULL;
static PxDefaultErrorCallback gDefaultErrorCallback;
static PxDefaultAllocator gDefaultAllocatorCallback;
bool recordMemoryAllocations = true;
physx::PxFoundation*  mFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, gDefaultAllocatorCallback, gDefaultErrorCallback);
physx::PxProfileZoneManager *mProfileZoneManager = &physx::PxProfileZoneManager::createProfileZoneManager(mFoundation);

int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE hprevinstance,PSTR pstrcmdline,int cmdshow)
{
	InitializePhysX();
	ShutdownPhysX();

	return 0;
}

void InitializePhysX() {
	
   gPhysicsSDK = PxCreatePhysics(PX_PHYSICS_VERSION, *mFoundation,physx::PxTolerancesScale(), recordMemoryAllocations, mProfileZoneManager );
   if(gPhysicsSDK == NULL) {
 cerr<<"Error creating PhysX device."<<endl;
 cerr<<"Exiting..."<<endl;
 exit(1);
   }
}
void ShutdownPhysX() {
   gPhysicsSDK->release();
}

Hi.

So…

You did almost everything wrong :D

Zero: Did you really learn how to code in C++ and link against the libs?
Without the knowledge above, it will takes really much time to understand why, what happend wrong,
why you get these funny errors, or linking errors or dont know why everything goes wrong…

Zero 2: You should really use a precompiled header. If you dont know them, you should learn everything about them.

After you know what they are and how to use them, you should add these lines to your pc - header:

#include <PxPhysicsAPI.h>
#include <PxPhysXCommon.h>
#include <PxDefaultSimulationFilterShader.h>
#include <PxDefaultCpuDispatcher.h>
#include <PxExtensionsAPI.h>
#include <PxRigidStatic.h>
#include <PxBroadcastingAllocator.h>
#include <PxProfileZoneManager.h>
#include <PxCooking.h>
#include <PxControllerManager.h>
#include <PsMutex.h>
#include <PxSimulationEventCallback.h>

First: You need to link against either a DEBUG or CHECKED or a RELEASE lib.
Linking against all of them will make much more trouble than you can imagine :(

You probably should read the Physx Guide.chm - to make sure what you really need and wich
version you should use.

( A hint: You are new with PhysX, so you should link against the DEBUG lib, because you will
have many error / warning messages when you are trying to do something invalid in PhysX. )

Second: After you read the guide, you should link against these libs: (put it in your pc - h.cpp)
(And copy the .dll to your bin folder, both DEBUG and CHECKED)

#pragma comment(lib,"PhysX3DEBUG_x86.lib")
#pragma comment(lib,"PhysX3CharacterKinematicDEBUG_x86.lib")
#pragma comment(lib,"PhysX3CommonDEBUG_x86.lib")
#pragma comment(lib,"PhysX3CookingDEBUG_x86.lib")
#pragma comment(lib,"PhysXProfileSDKDEBUG.lib")
#pragma comment(lib,"PxTaskDEBUG.lib")
#pragma comment(lib,"PhysX3ExtensionsDEBUG.lib")

Third: Read the PhysX guide. It really help.

Forth: Take a deep look into the samples - they have much code, (which is probably not the best way to start) but you really should look into it, change values, create actors etc to learn how PhysX works.

After that, you could try to code your project / test or what ever.

Thank you. That is exactly, what I was looking for !

And yes I never learned how to link against libs. Absoluty never. Actualy this is the first time I hear something like that. But I think that I know c++ very well.

You are welcome.

You didnt learn about to link against .libs?
So… you didnt use any .lib in every project / test you wrote?

Huh… thats a little scary I guess :D
You really should learn more about how to link, - what linking is, and how you do it correctly.
I would say that linking is one of the basics which should every programmer should know before
he / she whats to work (code) with libraries or engines…
Or even when he / she want to compile something. ( The knowledge behind the code :) )

I was alwasy using the d3d9.lib. I link it by the term #pragma comment(lib,“d3d9.lib”). This worked and, because diretx9 is so big everything was fine with this one library.

Now the code compiles. Now I am using the linker option : delay loaded dlls to link dlls. But I think, that this is not the right way. It works, but I think I should use something else.

Ok I have a new Problem. ScreenOfDeath, I am very grateful to you, that you are helping me.
I know, that I can load debuging information for Physx. But I don´t know how ? And I did not found the Debug libraries. I only found the Checked libraries. Are the Checked libraries ok for debuing? For example, when I debug the startup Project descibed in PhysxGuide.chm and I create a PxFoundation instance, the debugger says, that no symbolds are loaded for the Physx3Common_x86.dll. I do not know how I can use the Physx3CommonChecked_x86.dll instead of the Phyx3Commen_x86.dll.

You are welcome.

There is a common problem with the missing .pdb´s due to the fact that
the updated versions of it are only availabe when you have the source code (expensive, no need for it)
and compile them. The PhysX SDK isnt shipped with them (source and .pdb)

  • and I guess you really dont need them.
    You dont have to debug the source of PhysX - so you dont need them.

Of course, you can debug each line of your own code - even the code of the PxExtensions.
( PhysX have the source code to the extensions )

Its only a anoying warning that the compiler doesnt find them.
You can ignore them - with #pragma warning(disable: WARNINGNUMBERHERE).
I dont want to say its safe to ignore them - but it really seems to me.

The DEBUG libs are here: YourPhysXFolderPath\Lib\win32 (or win64) - and with the ending DEBUG.lib
(Example: PhysX3CommonDEBUG_x86.lib)

You dont have to use other dlls - you link against the .lib which automaticly select the associated .dll

(I guess there was a patched 3.2.3 version (to support VS 2012) which had the .pdb - but you can use them only in this version. But I´m not sure about it. Like I said above, its not necessary )