Linking PhysX in CMake project

Hi everyone,
I am new to PhysX, but I would like to start by creating a custom cmake project and link the physx libraries to it. After building PhysX on my linux machine I succesfully compiled the snippets. Then I simply copied the HelloWorld snippet in an external cmake project and tried to link the static PhysX libraries, but I am currently stuck there, because of some undefined references during the linking phase. I am linking through simple cmake command target_link_libraries, am I supposed to do something different? Does anyone have a sample CMakeLists template to do that?
Thanks!

Hi,
on linux the order of the linking libs does matter. This order should work, you can check the cmake file for the snippets:

Regards,
Ales

Yes that was it, thank you very much!

Hi,

I’m trying exactly the same thing and encountered linking issues for an external HelloWorld snippet (Ubuntu 18.04 x64).

I tried to follow the linux template to have link settings:


set(PHYSX_LIBRARIES libPhysXCommon_static_64.a libPhysX_static_64.a libPhysXFoundation_static_64.a libSnippetRender_static_64.a libSnippetUtils_static_64.a libPhysXExtensions_static_64.a)

link_directories(${PHYSX_ROOT_DIR}/physx/bin/linux.clang/debug/ /usr/lib/x86_64-linux-gnu)

target_link_libraries(SnippetHelloWorld {PHYSX_LIBRARIES} GL GLU glut X11 rt pthread dl -Wl,-rpath='{ORIGIN}’)

while still having many undefined reference errors. Am I still missing any libs?

As the previous user stated, in linux the order in which you link the libraries does matter. Try using the same order that appears in this file:

https://github.com/NVIDIAGameWorks/PhysX/blob/4.1/physx/snippets/compiler/cmake/SnippetTemplate.cmake

PhysXExtensions PhysX PhysXPvdSDK PhysXVehicle PhysXCharacterKinematic PhysXCooking PhysXCommon PhysXFoundation SnippetUtils

Oops, thought it was saying the order didn’t matter.

Resolved by following the template sequence. Thanks much.