HowTo: Setup PhysX SDK on Linux

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

PhysXbyNV_Black_200Nvidia PhysX can be run under Linux, but unfortunately there is not documentation how to do it. Binaries are available (only 32bit) but that’s all what is given to Linux users. I will describe step by step how to setup and begin development with PhysX in Ubuntu with use of Eclipse CDT. Users of other distributions and editors will find here useful informations too.

Article covers installation of PhysX SDK 2.8.1 and compiling sample program on 64bit machine (Ubuntu x86_64). On 32bit systems it will require little less effort so I will mark the parts which can be omitted on that systems with “64bit:” prefix.

Installation

First thing to do is download PhysX package from this site:  http://developer.nvidia.com/object/physx_downloads.html
It looks like Nvidia doesn’t provide packages for linux any more (because of coming sdk 3, they say), but you can still find it on Internet by googling for: PhysX_2.8.1_SDK_CoreLinux_deb.tar.gz or PhysX_2.8.1_SDK_CoreLinux_rpm.tar.gz

When you have package ready, go to download directory, unpack and install all packages.  64bit users will need to do it from command line to force installation.

64bit:

sudo dpkg -i --force-architecture *.deb

Shared libraries are installed in version specific directory “/usr/lib/PhysX/v2.8.1/”, so we need to link them to “/usr/lib”.

sudo ln -s /usr/lib/PhysX/v2.8.1/libNxCharacter.so.1 /usr/lib/libNxCharacter.so.1
sudo ln -s /usr/lib/PhysX/v2.8.1/libNxCooking.so.1 /usr/lib/libNxCooking.so.1
sudo ln -s /usr/lib/PhysX/v2.8.1/libPhysXCore.so.1 /usr/lib/libPhysXCore.so.1

PhysX is now installed and we can try run some samples from Nvidia which are placed in “/usr/sbin/PhysX_Samples_2.8.1_FC4/Bin/linux/”. Note that not all samples will work. I don’t know why they didn’t pay attention to make sure everything works. Source code for samples are not available on Linux too. Sample that should work is for example SampleBoxes.

/usr/sbin/PhysX_Samples_2.8.1_FC4/Bin/linux/SampleBoxes

Compile own project

So, now we have working PhysX, let’s try to compile something with use of it. I will describe how to do it with Eclipse CDT. You can get a gcc comand as well in the next paragraph (Although, for explanation of parameters read this section).

Before start, on 64bit machines ensure that you have 32bit gcc extensions installed:

64bit:

sudo apt-get install g++-multilib lib32stdc++6

Create a new C++ Empty Project and go to its properties. Go to “Settings” in “C/C++ Build” section. We will configure g++ flags to compile project properly. In “GCC C++ Compiler” in “Preprocessor” add these “Definied symbols”:

LINUX, NX32, CORELIB, NX_DISABLE_FLUIDS

(Last one is needed to make physics simulation work. I think it’s some kind of bug in PhysX but I’m not sure why it happens. I’ve found solution for it on some Italian or Spanish site so I could not understand what it was about.)

In “Directories”  enter these paths:

/usr/include/PhysX/v2.8.1/SDKs/Physics/include

/usr/include/PhysX/v2.8.1/LowLevel/API/include

/usr/include/PhysX/v2.8.1/SDKs/Cooking/include

/usr/include/PhysX/v2.8.1/SDKs/PhysXLoader/include

/usr/include/PhysX/v2.8.1/LowLevel/hlcommon/include

/usr/include/PhysX/v2.8.1/SDKs/Foundation/include

/usr/include/PhysX/v2.8.1/SDKs/NxCharacter/include

64bit: In “Miscellaneous” add flag to “Other flags”

64bit:

-m32

This flag tells compiler to make 32 bit binary instead of 64.

Now go to “GCC C++ Linker” and in “Libraries” add libs:

dl, pthread, PhysXLoader

GLU, GL, glut

Second line of libraries listed above are for OpenGL and GLUT, you’ll need them if you’re going to compile source code that I will list below.

64bit: In “Library search path” should be:

/usr/lib32

64bit: Same as in compiler section add flag in “Miscellaneous”

64bit:

-m32

Ok, enviroment set up properly, let’s compile something and see how it works. Because there is no sample code from Nvidia to try I’ve prepaired one taken from SDK for Windows and modified it a little for easier compilation under Linux. Here are source files: SampleBoxes.tar

And here is entire CTD project with proper configuration: SampleBoxesCDT.tar

Compile, run, enjoy.

Command line

You may also compile these sources from command line with:

g++ -DNX_DISABLE_FLUIDS -DCORELIB -DNX32 -DLINUX -I/usr/include/PhysX/v2.8.1/SDKs/Physics/include -I"" -I/usr/include/PhysX/v2.8.1/LowLevel/API/include -I/usr/include/PhysX/v2.8.1/SDKs/Cooking/include -I/usr/include/PhysX/v2.8.1/SDKs/PhysXLoader/include -I/usr/include/PhysX/v2.8.1/LowLevel/hlcommon/include -I/usr/include/PhysX/v2.8.1/SDKs/Foundation/include -I/usr/include/PhysX/v2.8.1/SDKs/NxCharacter/include -O3 -Wall -c -fmessage-length=0 -m32 -o"SampleBoxes.o" "./SampleBoxes.cpp"
g++ -L/usr/lib32 -m32 -o"physx_test"  ./SampleBoxes.o   -lPhysXLoader -lGLU -lGL -lglut -ldl -lpthread

Documentation

Last, very useful thing to do is install PhysX SDK Documentation viewer. The documentation files in PhysX packages for Linux are taken from Windows literally, so they are in Microsoft’s “.chm” extension and cover installation and setup under Windows, but still it’s very useful. PhysX API is platform independ. In Ubuntu there is a nice “.chm” file viewer “gnochm”. Documentation main file is “/usr/share/doc/libphysx-2.8.1/PhysXDocumentation.chm”

Maybe some day we will get drivers from Nvidia that run PhysX on GPU and better support for Linux. In near future there will be release of 3.0 PhysX SDK. It will support 64bit architectures natively.

Share this:
  • Print
  • email
  • del.icio.us
  • Digg
  • Technorati
  • StumbleUpon
  • Facebook
  • Twitter
Posted on June 27, 2009 at 2:16 am by Lubiluk · Permalink
In: Uncategorized · Tagged with: , , ,

13 Responses

Subscribe to comments via RSS

  1. Written by pro-rsoft
    on August 7, 2009 at 11:19 am
    Permalink

    Thank you very much for this helpful howto!

  2. Written by Kakuseysha
    on August 10, 2009 at 5:24 am
    Permalink

    Awesome article, very helpful!
    Is the character controller working on Linux? My samples are running, but some are broken, like Cloth simulation and soft bodies… I would like to know if it’s only on the samples, or it’s a bug on the Linux port of the engine.
    Thanks and congrats for the great blog, the design is nice and you write very well.

  3. Written by Lubiluk
    on August 12, 2009 at 12:24 pm
    Permalink

    I’m glad you liked this article.
    I haven’t checked every part of PhysX on Linux but so far I’ve noticed a few mystery things. I mentioned in howto that NX_DISABLE_FLUIDS must be definied to make simulation work.
    If it comes to not working samples, it seems they have missing files like images or object descriptions, that’s why they don’t work.
    I hope in 3.0 release of PhysX SDK Linux will get better support and documentation. I would really like to see an advanced and modern game on Linux.

  4. Written by ala_PANDA
    on September 15, 2009 at 3:26 pm
    Permalink

    Thx, man

  5. Written by ala_PANDA
    on September 25, 2009 at 8:15 pm
    Permalink

    Is it possible to use current distro of PhysX with Mingw on linux to cross-compile for windows?

    Regards, PANDA

  6. Written by Lewis McLane
    on August 19, 2010 at 10:25 am
    Permalink

    Hi!
    First of all thank you for the tutorial ;)

    I have one question for you:

    Which version of CDT do you use? (I’m not able to find some of the configuration senctions/tags you put)
    I’m actually using CDT 7.0 for Eclipse Helios and Physx SDK 2.8.3 (beta) for Linux.

    Thank you in advance.

  7. Written by Lubiluk
    on August 19, 2010 at 2:25 pm
    Permalink

    I don’t remember the version number (didn’t note it anywhere). That was a version from about year ago :) . All configuration fields should be in new version too.
    I think I will update this tutorial soon.

  8. Written by Dragon
    on November 21, 2010 at 11:42 pm
    Permalink

    Have you worked with RaycastCarController2? I am trying to simulate the dynamics of an omni-directional robot but can’t seem to find any source code for related samples. I am using PhysX on ubuntu,

    Your blog has been very helpful for my installation. Thanks.

  9. Written by Lubiluk
    on November 22, 2010 at 12:55 am
    Permalink

    No, I didn’t work with that.

  10. Written by chenna
    on February 22, 2011 at 8:51 pm
    Permalink

    Thank you. very useful and helpful.

  11. Written by Ayhan
    on April 24, 2011 at 4:23 pm
    Permalink

    I wonder if it’s possible to use the shared library(libNxCharacter.so, libNxPhysxCore.so etc.) to write a game on any linux for example Android.

  12. Written by Lubiluk
    on April 24, 2011 at 4:49 pm
    Permalink

    Unless NVidia starts to support Anroid it’s not very likely to run PhysX on these mobile devices. PhysX is shipped in binary packages, for Linux they are compiled for x86 architecture and only for NVidia GPUs. Android in most cases runs on ARMs.

Subscribe to comments via RSS

Leave a Reply