Compiling C++ code samples
This section explains how to compile the C++ code samples provided with Metavision SDK.
As an example, we take the Metavision Filtering sample from SDK Core Module. However, all other SDK samples can be compiled in the same way.
Based on this tutorial, you can compile any C++ SDK’s code sample or your own software using Metavision SDK.
Compilation on Linux
Warning
If you built Metavision from the source code of OpenEB or SDK without the deployment step, the following steps won’t apply as the source code of the samples won’t be deployed in /usr/local/share. In that case, the binaries of the sample can be found in SOURCE_DIR/build/bin after the compilation of the SDK.
So, if you want to compile a single sample, add --target sample_name
to the compilation command that you launch from the build
folder:
cmake --build . --config Release --target <sample_name>
First, make sure you installed CMake
and some required dependencies:
sudo apt -y install cmake libboost-program-options-dev libeigen3-dev libprotobuf-dev protobuf-compiler
Then, follow these steps:
make a working copy of the code sample, for example to your home directory:
cp -r /usr/share/metavision/sdk/core/cpp_samples/metavision_filtering/ ~/ # If you installed Metavision with SDK packages cp -r /usr/local/share/metavision/sdk/core/cpp_samples/metavision_filtering/ ~/ # If you built OpenEB or SDK source code with the deployment step
go to the directory with the code sample:
cd ~/metavision_filtering
compile the code:
mkdir build && cd build cmake .. -DCMAKE_BUILD_TYPE=Release cmake --build . --config Release
run the sample:
./metavision_filtering
Compilation on Windows
Setup
Warning
If you built Metavision from the source code without the deployment step, the following steps won’t apply as the
source code of the samples won’t be deployed in C:\Program Files\Prophesee\share
. In that case, the binaries of the samples
can be found in SOURCE_DIR\build\release
after the compilation of the SDK.
If you want to compile a single sample, add --target sample_name
to the compilation command that you launch from the build
folder:
cmake --build . --config Release --target <sample_name>
To compile the code sample, you will need to install some extra tools:
Microsoft Visual C++ compiler (MSVC, 64-bit version). You can choose one of the following solutions:
For building only, you can install MS Build Tools (free, part of Windows 10 SDK package)
Download and run “Build tools for Visual Studio (2022 or newer)” installer
Select “C++ build tools”, make sure Windows 10 SDK is checked, and add English Language Pack
To get a full development environment (with code editor), you can also download and install Visual Studio (2022 or newer)
Then, follow these steps:
open a command prompt
make a working copy of the code sample, for example to your home directory:
xcopy "C:\Program Files\Prophesee\share\metavision\sdk\core\samples\metavision_filtering" "%HOMEPATH%\metavision_filtering" /I
go to the directory with the code sample:
cd %HOMEPATH%\metavision_filtering
From here you can either compile the code from the command line directly, or you can create a Visual Studio project.
Compile from the command line
compile the code:
mkdir build && cd build cmake .. -DCMAKE_BUILD_TYPE=Release cmake --build . --config Release
run the sample:
cd %HOMEPATH%\metavision_filtering\build\release metavision_filtering.exe
Compile with Visual Studio
Follow these steps:
create a Visual Studio project (note, that this line works for Visual Studio 17 2022; change the command to match your installed version):
mkdir build && cd build cmake -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Release ..
This will create metavision_filtering.sln file in the build folder of your sample. Open this file with Visual Studio.
You can build the sample with Build -> Build Solution, or by pressing F7
Note that if you want to compile in debug mode, you must configure the lib path to
C:\Program Files\Prophesee\lib\*_d.lib
(see our page on Setting up IDE on Windows
You can then execute the software with Debug -> Start without debugging, or by pressing CTRL+F5
Ensure that Release and x64 are the selected solution configurations
Ensure that the selected sample is the startup project. You can do this by right-clicking on the project sample (metavision_filtering in this case, on the left under ALL_BUILD) and selecting Set as Startup Project