Writing your first C++ program with MRPT

The following are the instructions for creating new applications which use the MRPT C++ library, assuming that the library has been already built in any arbitrary user directory (or, optionally, installed in the system, e.g. /usr/include, etc.). See the instructions for building the library.

You can alternatively download already compiled versions for windows here, although it is highly recommended to recompile the whole library for your specific compiler and system.

This complete example (and others) can be found in the MRPT packages. See MRPT/doc/mrpt_example1/

1. Source files

Take a look at the list of existing libraries in MRPT and insert the appropriate includes for the libraries your code depends on (are you unsure about which MRPT libs do you need?):

If you prefer to explicitly refer to MRPT classes through their namespaces (e.g. mrpt::math::CMatrixFloat instead of CMatrixFloat), remove the using namespace statements.

For this first example, the complete code is: {MRPT_DIR}/doc/mrpt_example1/test.cpp

2. The CMake build system

Using CMake is the recommended, simplest way of generating a cross-platform application that uses the MRPT libraries. Create a file named CMakeLists.txt with the following content and save it in the path of your program (containing only “test.cpp” in this example):

 

If you are unsure about what MRPT libs to add in the “FIND_PACKAGE( MRPT REQUIRED …)” command, read this tutorial.

When CMake is invoked through:

in Linux/Mac, or

in Linux/Windows, you will be asked for the path of the file MRPTConfig.cmake, which should have been created in the process of building the MRPT library. Sometimes CMake automatically finds the MRPT directory and doesn’t even ask the user for the path. In Windows (for old versions of CMake) you will also have to set the variable wxWidgets_ROOT_DIR, if CMake is not able to find your wxWidgets directory automatically.

In Linux, and if MRPT has been installed in the system (/usr or /usr/local, or from synaptic), cmake will find automatically the MRPT configuration file without any additional arguments.

Note that for Linux/Mac you can see details about MRPT configuration with:

at the build directory.
3. What’s next?

You can try compiling one of the examples from the dozens available.