c++physx

How do you compile standalone snippets in Nvidia PhysX?


I started to test PhysX by experimenting on the basic Hello World snippet shipped by the program.

My installation is on Ubuntu 20.04.

As I understand the source code for

/home/ubuntu1/PhysX/physx/bin/linux.clang/release/SnippetHelloWorld_64

is located in

/home/ubuntu1/PhysX/physx/snippets/snippethelloworld

I tried to compile it by

clang++ -I/home/ubuntu1/PhysX/physx/install/linux/PhysX/include \
-I/home/ubuntu1/PhysX/physx/install/linux/PxShared/include \
SnippetHelloWorld.cpp

but I got an error

In file included from SnippetHelloWorld.cpp:39:
In file included from /home/ubuntu1/PhysX/physx/install/linux/PhysX/include/PxPhysicsAPI.h:45:
In file included from /home/ubuntu1/PhysX/physx/install/linux/PxShared/include/foundation/Px.h:37:
In file included from /home/ubuntu1/PhysX/physx/install/linux/PxShared/include/foundation/PxSimpleTypes.h:40:
/home/ubuntu1/PhysX/physx/install/linux/PxShared/include/foundation/PxPreprocessor.h:444:2: error: Exactly one of NDEBUG and _DEBUG needs to be defined!
#error Exactly one of NDEBUG and _DEBUG needs to be defined!
 ^
1 error generated.

Apparently, I should code within an environment. Almost all instructions of PhysX are for Windows using Visual Studio IDE.

Where should I define NDEBUG or _DEBUG when my aim is just to reproduce SnippetHelloWorld_64?

In other words, how can I experiment with HelloWorld in PhysX (by Linux command-line)?


Solution

  • These were the steps I used to build PhysX SDK on Ubuntu 18.04:

    Follow the instructions in the README.md and run generate_projects.sh and selected the option for linux, which generate cmake settings.

    Go into PhysX-4.1/physx/compiler/linux-debug and run make, this took around 10 mins on my laptop and compiled the SDK comprised of a lot of .o.

    And finally cd into PhysX-4.1/physx/bin/linux.clang/debug and you should be able to run ./SnippetHelloWorld_64 and other demos:

    SnippetHelloWorld_64

    EDIT:

    SnippetHelloWorld.cpp depends on a whole bunch of other files such as SnippetHelloWorldRender.cpp, stuff like cameras, collision detection code, and whatever else from the physx API is necessary to run that particular example are all located in other files. The make system automagically calibrates the necessary dependencies into one big command ie. g++ -I./include SnippetHelloWorld.cpp physx.o octree.a anotherdependency.x ... -o SnippetHelloWorld_64 etc ... to save you what you are attempting to do, which is manually resolve all the dependencies, which I wouldn't reccomend unless you are trying to extract the bare bones example with dependency out of the monolith API structure, in which case I would still use the make system at hand and slowly but surely remove parts of the API until you have a minimal example that is still building (reversing anytime it breaks along the way). Anyway, back to the make system. It is not just for building a library once, it is useful for continuous development in that you can make the first time, takes a long time because it builds everything, but then if you modify some files and run make again it will only recompile the files you have modified and rebuild the final executable, which is great for rapid development, experimenting and prototyping while having a well structured project structure. The reason the compiler is spitting out those errors is because those defines are basically compiler autogenerated for configuring make system (grep the debug symbols and see they are defined in a makefile).

    In short, use the make system, its what its there for. Unless, you have some reason that is dramatically different to what I have assumed in the answer, please specify it and I will try to help out, but afaik the make system is your friend in this, building the whole api once will be slow but make again and it will only build modified files.