This site uses cookies for functional purposes. To continue please read and agree to our Data Privacy.
By closing this message, you consent to our use of cookies on this device.

This tutorial shows in a very simple way how the component and program interaction is working and how additional programs can be used in an PLCnext application. The tutorial is intended for a beginner-level C++ programmer with experience in logic controller programming, and as a reference for practicians. Most important, the tutorial will distill the style of thinking that is necessary to avoid the common errors novice programmers make when they first come across PLCnext C++ programming.

This article shows how to prepare CMake toolchain files. Use them with CMake to compile for PLCnext devices.


Define the TOOLCHAIN_ROOT CMake variable to point to the installation directory of the PLCnext SDK. If the variable can't be not found the environment variables SDKROOT or PLCNEXT_SDK_ROOT will be used.

The target and native sysroot folders will be determined automatically dependening on the target device, the host system, and the processor architecture. To force the target and native sysroot, set the CMake variable TOOLCHAIN_TARGET_SYSROOT and TOOLCHAIN_NATIVE_SYSROOT or the environment variables OECORE_TARGET_SYSROOT and OECORE_NATIVE_SYSROOT to the path of the desired sysroot.

The TOOLCHAIN_PREFIX CMake variable can be set to point to additional search paths to find dependencies that are searched with the find_* command.


The toolchain files can be stored in a separate path, they don't have to be stored in the project folder. Be sure to also copy the cmake folder with the included CMake files next to the toolchain files. The toolchain file can then be used to set up the build system to build the project.

Linux host:

mkdir build
cd build
cmake \
  -G "Unix Makefiles"
  -D CMAKE_TOOLCHAIN_FILE=/path/to/toolchain/files/axf2152.cmake \
  -D TOOLCHAIN_ROOT=/opt/pxc/2.2.1 \
  -D TOOLCHAIN_PREFIX=~/pxc/dependencies

Windows host:

mkdir build
cd build
cmake ^
  -G "Unix Makefiles" ^
  -D CMAKE_MAKE_PROGRAM=c:/pxc/sdk/sysroots/x86_64-pokysdk-mingw32/usr/bin/make.exe ^
  -D CMAKE_TOOLCHAIN_FILE=c:/path/to/toolchain/files/axf2152.cmake ^
  -D TOOLCHAIN_ROOT=c:/pxc/sdk ^
  -D TOOLCHAIN_PREFIX=c:/pxc/dependencies ^

Following variables will be defined and cached from the toolchain file:

    The filename of the toolchain file. e.g. 'toolchain-file.cmake'
    The version of the toolchain file. e.g. '1.0.0'
    The targeted PLCnext controller of the toolchain file. e.g. 'AXCF2152'
    The path to the toolchain CMake helper modules.
    The architecture of the host system processor [x86, x86_64].

Variables to configure the toolchain:

    Path to the PLCnext toolchain root.
    Path to the PLCnext toolchain native sysroot.
    Path to the PLCnext toolchain target sysroot.
    Prefix path to add to CMAKE_FIND_ROOT_PATH.

Registered users can directly download CMake scripts at the end of this article.

Page 1 of 3

We have 91 guests and 3 members online