When you develop a C++ project and you want to use the Chrono API, you need to:
- include the necessary .h headers at compile time,
- link the necessary .lib libraries at link time,
- dynamically link the necessary .dll libraries at run time,
as shown below:
This process can be made almost automatic if you use CMake for building your program, see below.
1) Check prerequisites:
- CMake must be already installed on your computer.
- Chrono must be already installed and built on your computer, as explained here.
2) Create the project directory
- Copy the
template_projectdirectory to some place and rename it as you like. For example copy from
This will be the directory where you put your source code.
3) Edit the CMake script
- In the template directory there is already a CMakeLists.txt script. It will be used by CMake. Optionally you might edit it, see below.
and add the required module:
The same is done for other modules:
add_executable(myexe my_simulator.cpp my_foo_source.cpp my_bar_source.cpp)
4) Start CMake
- Start the CMake GUI
- Use Browse source... by setting the source directory that you created, ex:
- Use Browse build... by setting a new empty directory for the output project, ex:
- Press the Configure button in CMake
- When prompted to pick a generator, select the same compiler that you used to compile Chrono
- Important: set the
Chrono_DIRvariable. This is the cmake directory that you find in the directory where you built Chrono. In our example it is
- Press the Configure button again
6) Generate the project
- Press the Generate button in CMake. A project will be created in the build directory. In our example you will find it in
7) Compile the project
If you used a VisualStudio generator in CMake,
- Open the solution in VisualStudio editor (in our example double click on
- Change from Debug to Release mode, using the dropbox in the toolbar of VisualStudio
- Use the menu BUILD / Build solution... to compile and link.
If you used a Unix makefile generator in CMake (ex. in Linux), you can open a shell, cd into the build directory and call make:
8) Run your program
By default all binaries (ex. myexe.exe) of your project will go into your build directory, in our example
C:\my_project_build\Debug\my_project.sln if you decided to compile in Debug mode).
- double click on the .exe file and you should see the demo running in an interactive 3D view
For Windows users, some notes on copying the Chrono DLL:
- Your executable need to know where to find the needed .dll[s], otherwise it will crash as soon as you try to run it.
- To make things simple, at the end of the default CMakeFile.txt used in this example there is this instruction:
add_DLL_copy_command macro. This takes care of automatically copying all the needed dlls right after each build. It also copies the Irrlicht.dll into your executable directory, if unit_IRRLICHT is used.
add_DLL_copy_command macrofeature is not working properly when in Debug mode. In fact it always copies the Release ddls of Chrono even in the Debug/ build directory of your project, and this will cause the program to crash.
As a temporary workaround, if you want to compile your program in Debug/, please copy all the .dll files of the Chrono build directory (ex. from
This is not necessary for builds in Release mode.