Getting started with PhysX SDK 3.0 on Linux

Nvidia has released PhysX SDK 3.0 with new features/changes and promised native support for 64-bit machines (Official release notes). Amongst, SDK packages there is also one for Linux. Unfortunately Nvidia again doesn’t ship any documentation or samples for Linux users. But that won’t stop us.
Putting all the PhysX parts together is quite cumbersome task, therefore in this entry I will show you how to set up the SDK and compile a simple sample PhysX code.

Getting the SDK

PhysX SDK 3.0 can be downloaded from Nvidia developer suppor center: http://supportcenteronline.com/ics/support/DLRedirect.asp?fileID=111953. You need to have an account there in order to download packages (it’s free).  (By the way, passwords on this site are stored non-hashed…)

Extract the package in your filesystem and prepare your editor or IDE for hacking. I extracted the SDK into /opt/PhysXSDK and I will use that location in the rest of this article.

The SDK consists of include files, static libraries and some c++ source files.

I recommend you to download PhysX SDK for Windows as well, because it contains documentation in .chm files and samples which are missing in Linux package.

Compiling a simple program

Sample PhysX 3.0 program screenshot We need some sample code to play with it’s compilation. Samples provided with the SDK (in Windows packgage) are far more complicated than in previous releases, therefore instead of trying to compile one of them I’ve picked one very simple sample code from the internet. I’ve found a nice simple program on this site: http://mmmovania.blogspot.com/2011/05/simple-bouncing-box-physx3.html?utm_source=BP_recent. The only thing that it does is dropping a cube on the ground, but more important is that, it performs all needed PhysX initializations. I have modified the source file slightly such that it can be compiled under Linux with gcc. You can obtain the modified file here: SampleBox.cc

In order to compile the file we need to set up 4 things: defined symbols, include paths, library paths and link flags.

Find appropriate (preprocessor and linker) settings of your project in your IDE or enter flags for compiler in command line.

  1. The only one symbol that has to be defined is either _DEBUG (for debug mode) or NDEBUG. Only one of them may be defined at a time.  Apropriate preprocessor flag is:
    -D_DEBUG or -DNDEBUG
  2. Next we need to set up include paths for PhysX header files. Note that it’s not a complete set of PhysX includes. If you will use some other header files that are not included here remember to add apropriate paths for preprocessor. Aslo, it is better to not use depracated functionalities from the last include directory.
    -I/opt/PhysXSDK/SDKs/PhysXAPI \
    -I/opt/PhysXSDK/SDKs/PhysXAPI/extensions \
    -I/opt/PhysXSDK/PhysXFoundationSDK \
    -I/opt/PhysXSDK/pxtask/include \
    -I/opt/PhysXSDK/SDKs/PhysXAPI/deprecated

    The backslash sign is for proper escaping line breaks in makefiles. You don’t need that if you just enter these flags inline.

  3. Now let’s tell the linker where to find PhysX libraries. All of them are in just two directories. If you are on 32-bit machine change directory name from linux64 to linux32.
    -L/opt/PhysXSDK/SDKs/lib/linux64 \
    -L/opt/PhysXSDK/pxtask/lib/linux64
  4. Last thing to do is instruct the linker to link our program against PhysX libraries. To do so enter following flags:
    -lpthread \
    -lrt \
    -lPhysX3 \
    -lSimulationController \
    -lLowLevel \
    -lPhysXProfileSDK \
    -lPhysX3Extensions \
    -lFoundation \
    -lSceneQuery \
    -lPhysX3Common \
    -lPhysX3CharacterKinematic \
    -lPhysX3Vehicle \
    -lPhysX3Cooking \
    -lPhysX3MetaData \
    -lGeomUtils \
    -lPvdRuntime \
    -lRepX3 \
    -lPxTask

    It seems that order of these flags may have some influence on linking success. The above set works.

The file provided for this entry uses OpenGL and Glut libraries, so you need to provide following linker flags as well:

-lgl -lglu -lglut

Also make sure that you have these libraries installed.

Now spawn the compiler and enjoy your PhysX program running in your favourite OS!

For those who use Anjuta IDE or Autotools I attach configured Anjuta project: physx3-demo.tar.gz

Sources:
http://mmmovania.blogspot.com/2011/05/simple-bouncing-box-physx3.html?utm_source=BP_recent
http://forums.developer.nvidia.com/index.php?showtopic=6396
http://forums.developer.nvidia.com/index.php?s=21e9323c0ddf3f7d9d08cd96b9ba98ed&showtopic=6267&st=0

Share this:
  • Print
  • email
  • del.icio.us
  • Digg
  • Technorati
  • StumbleUpon
  • Facebook
  • Twitter
Posted on July 18, 2011 at 8:39 pm by Lubiluk · Permalink
In: Uncategorized · Tagged with: , ,

One Response

Subscribe to comments via RSS

  1. Written by Deveng shui » HowTo: Setup PhysX SDK on Linux
    on July 18, 2011 at 8:55 pm
    Permalink

    [...] Note: This article is about PhysX 2.8.1. A guide for PhysX 3.0 is here. [...]

Subscribe to comments via RSS

Leave a Reply