Build C++ projects with Open3D¶
This page explains how to create a CMake based C++ project using the Open3D C++ interface.
For help on the C++ interfaces, refer to examples in [examples/cpp/Test], [examples/cpp/Experimental] and [src/Tools] folder and check Doxygen document for C++ API.
Create C++ project¶
Let’s create a basic C++ project based on CMake and Open3D installed libraries and headers.
Get the code from
Get the CMake config file from
Build the project using the following commands:
mkdir -p build cd build cmake -DCMAKE_PREFIX_PATH="<Open3D_install_path>/lib/cmake/" .. make -j
CMAKE_PREFIX_PATH option is used to tell the CMake where to look for the Open3D installed files.
For example, if Open3D was installed to
~/open3d_install, the cmake command would look like this:
cmake -DCMAKE_PREFIX_PATH="~/open3d_install/lib/cmake/" ..
The steps for creating a C++ project based on the Open3D installed libraries and headers on Windows is very similar.
Open CMake GUI and set the source folder to
C:/testVisualizerand the binaries folder to
At this time you will see that CMake is unable to find Open3D.
For simplicity the Open3D install location is
In order for CMake to find the Open3D installed files you need to set
Open3D_DIR to the location of the Open3D installed CMake files which is
Configure. CMake finds Open3D.
Generate. Open the TestVisualizer project and build.
Alternatively, this can be done by calling CMake from the console:
cd Open3D mkdir build cd build cmake -G "Visual Studio 16 2019 Win64" -DCMAKE_INSTALL_PREFIX=C:\open3d_install .. cmake --build . --parallel %NUMBER_OF_PROCESSORS% --config Release --target install cd ..\docs\_static\C++\ mkdir build cd build cmake -G "Visual Studio 16 2019 Win64" -DCMAKE_PREFIX_PATH=C:\open3d_install .. cmake --build . --parallel %NUMBER_OF_PROCESSORS% --config Release Release\TestVisualizer.exe
The following fragment from
CMakeLists.txt shows how to specify hints to CMake when looking for the Open3D installation.
This technique is required when installing Open3D to a user location rather than to a system wide location.
This section of the
CMakeLists.txt specifies the installed Open3D include directories, libraries and library directories.