Build a C++ “Hello World” Application With Reference to Zivid API in Visual Studio in Windows

Introduction

This tutorial shows how to create and start developing a C++ application for Zivid in Visual Studio 2017.

Requirements

Note

The CMake version that is tested is 3.15.3.

Instructions

Step by step instructions are provided with screenshots below.

Create ZividHelloWorld.cpp and CMakeLists.txt

The destination used for this tutorial is "C:/Users/Public/Documents/ZividHelloWorld"

#include <Zivid/Zivid.h>
#include <iostream>

int main()
{
    try
    {
        Zivid::Application zivid;
        std::cout << "Hello Zivid World!" << std::endl;
    }
    catch(const std::exception &e)
    {
        std::cerr << "Error: " << Zivid::toString(e) << std::endl;
        return EXIT_FAILURE;
    }
}
project(ZividHelloWorld)

cmake_minimum_required(VERSION 3.3.2 FATAL_ERROR)

set(CMAKE_CXX_STANDARD 11)

find_package(
    Zivid
    COMPONENTS Core
    REQUIRED)

add_executable(${PROJECT_NAME} ${PROJECT_NAME}.cpp)

target_link_libraries(${PROJECT_NAME} Zivid::Core Zivid::Visualization)

Configure the solution with CMake

Run CMake (cmake-gui.exe), then set the top two entries:

Where is the source code

C:/Users/Public/Documents/ZividHelloWorld

Where to build the binaries

C:/Users/Public/Documents/ZividHelloWorld/build

Screenshot of CMake GUI with configuration for Zivid sample.

Click Configure. When prompted, click Yes to create a new build directory.

Screenshot of CMake GUI with a note about creation of build directory.

Set the top two entries:

Specify the generator for this project

Visual Studio 15 2017

Optional platform for generator

x64

Screenshot of CMake GUI where you specify generator.

Click Configure.

If the value Zivid_DIR is empty, add C:/ProgramFiles/Zivid/CMake/Zivid to it, as shown in the figure below.

Screenshot of CMake GUI configuration.

Click Configure again.

Screenshot of CMake GUI configuration done.

Click Generate.

Screenshot of CMake GUI generation.

Click Open Project.

Build the solution

Build the solution by pressing Ctrl + Shift + B.

Screenshot of build events in Visual Studio.

Run the program

On the right side, right click on ZividHelloWorld, then click Set as StartUp project.

Screenshot of Visual Studio

Run the program by pressing F5 key.

Screenshot of console output from program run from Visual Studio.