‹ Back to Tutorials

Building OpenNN

OpenNN is a C++20 library for building, training and deploying neural networks. The project uses CMake and can be built from the terminal or with Visual Studio.

Contents:

Terminal (Ubuntu)

This is the recommended way to build OpenNN on Ubuntu. The commands below use a separate build directory, leaving the source tree clean.

1. Install the build tools

On Ubuntu 24.04 or newer, install GCC, CMake, Ninja and Git:

sudo apt update
sudo apt install -y build-essential cmake ninja-build git

Check that the tools are available:

g++ --version
cmake --version
ninja --version

OpenNN requires a compiler with C++20 support and CMake 3.24 or newer.

2. Download OpenNN

git clone https://github.com/Artelnics/opennn.git
cd opennn

3. Configure the project

Start with a CPU Release build that includes the examples:

cmake -S . -B ../opennn-build -G Ninja \
  -DCMAKE_BUILD_TYPE=Release \
  -DOpenNN_DISABLE_CUDA=ON \
  -DOpenNN_BUILD_TESTS=OFF \
  -DOpenNN_BUILD_EXAMPLES=ON

During the first configuration, CMake downloads the required third-party dependencies, so an internet connection is needed.

4. Build and run an example

Build the Iris plant example:

cmake --build ../opennn-build --target iris_plant --parallel

Run it from the build bin directory so that its relative data path is resolved correctly:

cd ../opennn-build/bin
./iris_plant

To compile the full configured project instead, use:

cmake --build ../opennn-build --parallel

For GPU support, install the CUDA Toolkit and cuDNN 9 or newer, then configure the project with -DOpenNN_DISABLE_CUDA=OFF.

Visual Studio

Use Visual Studio 2022 with the Desktop development with C++ workload and the CMake tools for Windows installed.

1. Download OpenNN

Open a Developer PowerShell for Visual Studio 2022 and clone the repository:

git clone https://github.com/Artelnics/opennn.git
cd opennn

2. Generate the Visual Studio solution

Generate a 64-bit CPU build in a separate directory:

cmake -S . -B ..\opennn-build `
  -G "Visual Studio 17 2022" `
  -A x64 `
  -DOpenNN_DISABLE_CUDA=ON `
  -DOpenNN_BUILD_TESTS=OFF `
  -DOpenNN_BUILD_EXAMPLES=ON

CMake creates OpenNN_Project.sln in the opennn-build directory. You can build from Developer PowerShell or open the solution in Visual Studio.

3. Build and run an example

From Developer PowerShell, build the Iris plant example in Release mode:

cmake --build ..\opennn-build --config Release --target iris_plant --parallel
cd ..\opennn-build\bin
.\Release\iris_plant.exe

If you use the Visual Studio interface, select Release and x64, then set iris_plant as the startup project and build it.

Set an OpenNN example as the Visual Studio startup project
Select the Release configuration in Visual Studio
Build the Iris plant OpenNN example in Visual Studio
Run the Iris plant OpenNN example

4. Create your own application

The examples/blank/main.cpp file is a minimal starting point for a new OpenNN application. Edit it and build the blank target:

cmake --build ..\opennn-build --config Release --target blank --parallel
Blank OpenNN application in Visual Studio

References