Setting Up a Bullet Application

Downloading

First, you need to download the Bullet Physics library. The latest release at the time of writing is version 2.82. You can also get the source from the SVN repository (Bullet 2.x), or the GitHub repository (Bullet 3.x in development). Extract the content. The resulted folder does not contain the compiled library, but only the source. In my case, the source folder is D:\tuto\bullet-2.82-r2704.

The next step is to compile Bullet from the source in order to use it in our C++ projects. In this documentation, we will only show you how to build Bullet for the MinGW (GCC) compiler (regular Unix Makefiles are similar), but Bullet also supports Visual Studio and Mac. For these platforms, see the article on the official wiki.

Preparing Makefiles using CMake

We will use CMake to prepare the Makefiles in order to compile Bullet into C++ binaries. CMake is a building tool that makes the building process simpler in different operating systems. You can get it here on its official website, under the Binary distributions section. These procedures can be followed not only to compile Bullet Physics, but also any other libraries that can be compiled with CMake.

Create a folder next to your Bullet source folder. For example, D:\tuto\bullet-2.82-r2704-build. This will contain the compiled files.
Open CMake-gui. Next to Where is the source code:, browse to the source folder. Next to Where to build the binaries:, browse to the new empty folder. This looks like this:

Source and build directories in CMake

After that, click on Configure. CMake will ask to choose the Generator to use. In our case, we will select MinGW Makefiles. Click on Finish. CMake will some process some configuration and display the line Configuring done at the end of the bottom text box.

If you get the error “Could NOT find GLUT (missing: GLUT_INCLUDE_DIR)”, see the section below.

Once you are ready, click on Generate.

Compiling with MinGW

But before continuing, make sure you have MinGW installed in your computer (Download Installer button at the top right on the home page).

Then open your terminal (On Windows: Windows+R then type cmd), cd to your build folder (cd D:\tuto\bullet-2.82-r2704-build), and execute the make command (mingw32-make.exe). It will compile the Bullet library files for several minutes.

Once it is done, the generated library files can be found at bullet-2.82-r2704-build\lib.

Could NOT find GLUT (missing: GLUT_INCLUDE_DIR)

First, note that Glut is only used in the demo executables of Bullet. The library itself does not use Glut. Thus, if you do not need to compile the demos you can just uncheck the option BUILD_DEMOS and ignore the message.

Otherwise, if you get this error and you want the demos, open CMakeLists.txt in the source folder (D:\tuto\bullet-2.82-r2704\CMakeLists.txt) and add at the end:

#fix for glut not found
INCLUDE_DIRECTORIES(${BULLET_PHYSICS_SOURCE_DIR}/Glut)
SET(GLUT_glut_LIBRARY ${BULLET_PHYSICS_SOURCE_DIR}/Glut/glut32.lib)

These lines will force CMake to use the Glut files included in the Bullet source folder. The message in CMake will not disappear, but this should fix the problem at compilation time.

Creating the project

Here are the instructions to create a C++ project with Bullet with the IDEs Eclipse CDT and Code::Blocks. The steps are similar for other IDEs.

With Eclipse CDT

If your toolchain is not listed, uncheck Show project types and toolchains only if they are supported on the platform.

The next step is to setup Bullet into the project.

Include directory settings in Eclipse
Libraries settings in Eclipse

With Code::Blocks

Note: You can also add the libraries under Link libraries. These libraries must be in the exact order since one depends on the next one.

Libraries settings in Code::Blocks
...the include directory
...and the libraries directory

Now, you are ready to write your first Bullet application.

Hello World Application

The official Bullet Physics wiki has a very good article for a Hello World.