C (Windows)

You are viewing an old version of the documentation. You can switch to the documentation of the latest version by clicking the top-right corner of the page.

In this chapter, you will learn to configure the samples of C APIs in Mech-DLK SDK with CMake and Visual Studio on a Windows operating system.

Sample List

We provide two categories of samples: Basic and Advanced.

  • Basic: samples using single models exported from Mech-DLK to do inference of single images as well as obtain and visualize results.

  • Advanced: samples for simultaneous inference of multiple images and inference of cascaded models.

Basic

Advanced

Prerequisites

The prerequisites for the use of C samples in Mech-DLK SDK are as follows:

  • Install the required software.

  • Add related environment variable.

Install Required Software

Before using the C samples in Mech-DLK SDK, you should install Mech-DLK SDK, CMake, and Visual Studio.

Install the Latest Version of Mech-DLK SDK

Please install the Mech-DLK SDK and the third-party libraries and resources it depend upon according to Installation Guide.

Install CMake (Version 3.2 or Above)

  1. Download CMake: Select the installer to the right of Windows x64 Installer.

    cmake download
  2. During installation, select the following two options so that CMake can be added to environment variables, and a desktop icon can be created for CMake.

cmake 1

Install Visual Studio (Version 2017 or Above)

  1. Download the Visual Studio installer.

  2. During installation, please select “Desktop development with C++” in the Desktop & Mobile category. Then, click Install in the lower-right corner.

sample c workload

Add Environment Variable

You can add the related environment variable by the following steps:

  1. Right-click This PC on the desktop and select Properties.

  2. Click Advanced system settings and on the Advanced tab of the pop-up System Properties dialog box, click Environment Variables to open the Environment Variables dialog box.

  3. In the System Properties box, scroll to Path and double-click it to show the Edit System Variable dialog box.

  4. Click New in the upper-right corner, add the path to Mech-DLK SDK, i.e., xxx\mechdlk_sdk, and then click Move Up to move the variable to the top. After that, click OK.

It is recommended to restart your computer after the installation; otherwise, the environment variable added may not take effect.

Build and Run Samples

You can build all samples at a time.

Configure Samples in CMake

  1. Double-click the CMake desktop icon to open the software.

  2. Enter or select the path to the source code and the path to build the binaries. For the path to build the binaries, you can add \build right after the path to the source code if there isn’t one and continue the configuration.

    Where is the source code

    xxx\mechdlk_sdk\samples\c

    Where to build the binaries

    xxx\mechdlk_sdk\samples\c\build

  3. Click Configure. When you first click the Configure button, a window will pop up to confirm whether you want to create the build folder. Click Yes to create the folder.

    create build

    Then, you will enter the configuration window. Select the Visual Studio version and click Finish.

    configuration

    When the configuration completes, the statement Configuring done will appear in the last line of the log.

    c windows configuring done
  1. Click Generate to generate Visual Studio solutions. When the generation completes, the statement Generating done will appear in the last line of the log. Then, click Open Project to open the solutions in Visual Studio.

    c windows generating done
You can also open the created build folder (path: xxx\mechdlk_sdk\samples\c\build), find MechDLKSDKCSamples.sln, and double-click it to open the solutions in Visual Studio.

Build Samples in Visual Studio

  1. On the Visual Studio toolbar, confirm that the solution configuration is Release. Currently, DLL files for Debug are unavailable.

  2. Click Build  Build Solution. An executable file in the EXE format is generated for each sample. The executable files are saved to the Release folder, located in the Where to build the binaries path that you entered in CMake.

    generate solution
  3. Copy and paste the resources folder to the following path:

    • xxx\mechdlk_sdk\samples\c\build\Release

  4. Copy all files in the 3rd_dll folder under the project folder and all files in the path xxx/mechdlk_sdk/dll and paste them to the path xxx\mechdlk_sdk\samples\c\build\Release.

Run Samples

You can run the samples in Visual Studio after building them, or you can run the samples by double-clicking the executable files.

Run a Sample in Visual Studio

  1. In the Solution Explorer panel, right-click a sample and select Set as Startup Project.

    startup project
  2. Click debugger windows on the toolbar to run the sample.

Run the Executable File of a Sample

Open the Release folder and double-click the EXE file named after the sample to run the sample and obtain results.

We Value Your Privacy

We use cookies to provide you with the best possible experience on our website. By continuing to use the site, you acknowledge that you agree to the use of cookies. If you decline, a single cookie will be used to ensure you're not tracked or remembered when you visit this website.