# Building and Using Jolt Physics ## Build Types Each platform supports multiple build targets - Debug - Debug version of the library, turns on asserts - Release - Release version of the library, no asserts but includes profiling support and can draw the world and simulation properties - ReleaseASAN - As Release but turns on Address Sanitizer (clang only) to find bugs - ReleaseUBSAN - As Release but turns on Undefined Behavior Sanitizer (clang only) to find bugs - ReleaseCoverage - As Release but turns on Coverage reporting (clang only) to find which areas of the code are not executed - Distribution - Shippable version of the library, turns off all debugging support ## Includes The Jolt headers don't include Jolt/Jolt.h. Always include Jolt/Jolt.h before including any other Jolt header. You can use Jolt/Jolt.h in your precompiled header to speed up compilation. ## Defines There are a number of user configurable defines that turn on/off certain features:
General Options (click to see more)
CPU Instruction Sets (click to see more)
## Logging & Asserting To override the default trace and assert mechanism install your own custom handlers in Trace and AssertFailed (see IssueReporting.h). ## Custom Memory Allocator To implement your custom memory allocator override Allocate, Free, AlignedAllocate and AlignedFree (see Memory.h). ## Building
Windows 10+
Linux
Android
macOS
iOS
## Other Build Tools * A vcpkg package is available [here](https://github.com/microsoft/vcpkg/tree/master/ports/joltphysics). * A xmake package is available [here](https://github.com/xmake-io/xmake-repo/tree/dev/packages/j/joltphysics). * Jolt has been verified to build with [ninja](https://ninja-build.org/) through CMake. ## Errors ### Link Error: File Format Not Recognized If you receive the following error when linking: ``` /usr/bin/ld: libJolt.a: error adding symbols: file format not recognized ``` Then you have not enabled interprocedural optimizations (link time optimizations) for your own application. See the INTERPROCEDURAL_OPTIMIZATION option in CMakeLists.txt. ### Link Error: Unresolved External Symbol If you receive a link error that looks like: ``` error LNK2001: unresolved external symbol "public: virtual void __cdecl JPH::ConvexShape::GetSubmergedVolume(...) const" ``` you have a mismatch in defines between your own code and the Jolt library. In this case the mismatch is in the define `JPH_DEBUG_RENDERER` which is most likely defined in `Jolt.lib` and not in your own project. In `Debug` and `Release` builds, Jolt by default has `JPH_DEBUG_RENDERER` defined, in `Distribution` it is not defined. The cmake options `DEBUG_RENDERER_IN_DEBUG_AND_RELEASE` and `DEBUG_RENDERER_IN_DISTRIBUTION` override this behavior. The `RegisterTypes` function (which you have to call to initialize the library) checks the other important defines and will trace and abort if there are more mismatches. ### DirectX Error The samples use DirectX for the graphics implementation, when attempting to run the samples you may get a DirectX error pop-up which may say "The GPU device instance has been suspended", in your debugger you may see the message "Using the Redistributable D3D12 SDKLayers dll also requires that the latest SDKLayers for Windows 10 is installed.". Fix this by enabling "Graphics Tools" which is an optional Windows settings. To enable it you have to press the windows key, search for "Manage Optional Features", and then click "Add a Feature", and install "Graphics Tools". ### Illegal Instruction Error If your CPU doesn't support all of the instructions you'll get an `Illegal instruction` exception. On Linux to see what instructions your CPU supports run `lscpu` and then look at the flags section, on Windows you can use a program like [`coreinfo`](https://learn.microsoft.com/en-us/sysinternals/downloads/coreinfo). Once you know what instructions your cpu supports you can configure the project through cmake and for example disable all special instructions: ``` ./cmake_linux_clang_gcc.sh Release clang++ -DUSE_SSE4_1=OFF -DUSE_SSE4_2=OFF -DUSE_AVX=OFF -DUSE_AVX2=OFF -DUSE_AVX512=OFF -DUSE_LZCNT=OFF -DUSE_TZCNT=OFF -DUSE_F16C=OFF -DUSE_FMADD=OFF ``` Note that this example is for Linux but the cmake settings work on Windows too. ## Doxygen on Windows Documentation can be generated through doxygen: - Install Doxygen (https://www.doxygen.nl/download.html) - Run: run_doxygen.bat