Environment Setup

The main tool for building, testing and deploying software is CMake. It is widely accepted and supported by many IDEs, which means that the user is free to choose from various development environments.

To make things more convenient, there are Motorcortex plugins for VSCode and CLion. While the same setup can be done manually, these plugins simplify the process and provide templates to get started quickly. Thus, VSCode and CLion are the recommended IDEs for developing Motorcortex Control applications.


Installing Motorcortex Extensions

You can find the installation guide for the Motorcortex VSCode extension here.

Setting up the Project

As the Motorcortex VSCode extension requires to know that you are creating a control application, you need to either create a new project or setup an existing project:

Creating a New Motorcortex C++ Control Project

Use the button scaffold new Motorcortex C++ Control Application in the Motorcortex extension view to create a new Motorcortex C++ Control application. This will create a new folder with the necessary files and structure for a Motorcortex Control application.

image not found

You can also use the command palette (ctrl+shift+p) and search for Motorcortex: Create C++ MCX Control App.

When you have created the project, open the folder in VSCode. The extension view should now show that a Motorcortex Control application is detected.

image not found

Setting up Toolchain

To build your project, you have three options based on your development setup:

  • Cross Remote Toolchain - Build on Local (preferred):

    This creates a toolchain that builds the application on your local machine and deploys it to the target device for execution. Uses the Motorcortex cross-remote SDK.

  • Cross Remote Toolchain - Build on Target:

    This creates a toolchain that builds the application on the target device itself, while you develop on your local machine. Uses the Motorcortex cross-remote SDK for IntelliSense.

  • Remote toolchain (Remote Development) - Build on Target:

    This creates a toolchain that builds and runs the application on the target device itself, while you develop on your local machine. Uses VSCode Remote Development extension-pack, which is preinstalled with the Motorcortex extension.

The Cross Remote Toolchains both require the same setup as the distinction where the builds happens is done in the VSCode Extension.


This is the prefered way to develop Motorcortex control applications remotely. It uses the Motorcortex Cross-Remote SDK to provide IntelliSense and build support on your local machine, while deploying and running the application on the target device.

Prerequisites

From the Motorcortex store download the latest Motorcortex SDK for your system, for example mcx-rtos-glibc-x86_64-mcx-image-dev-corei7-64-mcx-intel-toolchain-2025.03-0-g0e9d0e9.sh.

Installing

  1. Press the Configure Toolchain button in the Motorcortex extension view and choose Cross-Remote.
image not found
  1. Choose whether to use a DevContainer or not. Using a DevContainer is recommended as it provides a consistent development environment. It is a built-in feature of VSCode and works cross-platform. If you choose to not use a DevContainer, make sure that you have all the required dependencies installed on your local machine.

  2. Configure the Remote path and executable name.

    • Remote Path: The path on the target device where the executable and configs will be synced to run/debug on the device. When building remotely, the entire workspace will be synced to this path.
    • Executable Name: The name of the executable file that will be built and run on the target device. Make sure that this matches the name defined in your CMakeLists.txt file!
  3. Depending on whether you chose to use a DevContainer or not, select the appropriate file:

    • DevContainer: SDK install file: **.sh
    • Not DevContainer: Environment file: mcx-clion-environment in the installed SDK folder.
  4. Open the DevContainer (if chosen) by pressing the Reopen in Container button in the bottom right corner of VSCode.

  5. Select the CMake Kit: ctrl+shift+p: CMake: Select a KitMotorcortex Cross-Remote

Usage

You can now build and run/debug your Motorcortex control application remotely using the VSCode build and debug features. The Motorcortex extension will handle the deployment and execution on the target device automatically. Convenient buttons have been added to the VSCode Extension view in the sidebar for easy access.

image not found

The buttons use Tasks and Launches that have been added to the .vscode folder to also provide a vscode-native way of developing.


This way to develop Motorcortex control applications is completely on the target machine. Only the VSCode UI will run on your local machine. The files will be stored on the target and even the terminals inside of VSCode will be running inside of the target. This issues with Git might occur.

Installing

  1. Open the Remote Explorer and select Remotes (Tunnels/SSH) in the top bar:

    image not found
  2. Add a new remote by clicking on the + icon next to SSH and follow the instructions to set up an SSH connection to your target machine.

  3. Once the connection is set up, Open the newly created SSH Connection and either open it in the current window or in a new window.

  4. Download the Motorcortex Extension again.

  5. Transfer your project files to the target machine if you haven’t done so already or create a new project.

  6. Press the Configure Toolchain button in the Motorcortex extension view and choose Cross-Remote.

image not found
  1. Select Remote Toolchain and enter the name of the executable. Make sure that this matches the name defined in your CMakeLists.txt file!

Settings

For ease of use, the sidebar Motorocortex view shows the relevant settings for the selected toolchain. You can change these settings here directly.

All settings for both Toolchains:

  • motorcortex.targetIp - IP address of your Motorcortex Target controller
  • motorcortex.targetUser - SSH username for your Motorcortex Target controller
  • motorcortex.cpp.default_args - Default program arguments when running/debugging
  • motorcortex.cpp.executable_name - Name of the executable to build and run on the target controller
  • motorcortex.cpp.crossRemoteToolchain.sdk_installer_path - Path to the MotorCortex SDK installer (.sh file) for remote toolchain setup. Leave empty to be prompted each time.
  • motorcortex.cpp.crossRemoteToolchain.remote_path - Remote path on the controller where files will be synced
  • motorcortex.cpp.cmake_toolchain_path - Path to the CMake toolchain file for cross-compiling C++ Motorcortex Control Applications
  • motorcortex.cpp.mcx_packaging_install_prefix - Path prefix for installing MCX Packaging on the Motorcortex Target device

Troubleshooting

Error: “MainControlLoop.h: No such file or directory”

  • This means you’re trying to compile with g++ directly
  • Use CMake build tasks instead

Error: “mcx/core.h: No such file or directory”

  • Make sure the SDK is installed correctly if you are using Remote Toolchain.
  • Make sure Motorcortex installed on the controller. Deploy an Application if you are using Remote Development Toolchain.
  • Make sure your motorcortex.cpp.cmake_toolchain_path setting is correct and points to the SDK toolchain file
  • (if building works but IntelliSense fails) Make sure to have selected the correct CMake Kit: ctrl+shift+p: CMake: Select a KitMotorcortex Cross-Remote

Cannot find executable when debugging

  • Make sure to build first (Ctrl+Shift+B)
  • Check that build/**-debug/motorcortex_control_app_docs or build/**-release/motorcortex_control_app_docs exists

Breakpoints not working (red/unbound)

  • Ensure you’re using the Debug configuration, not Release
  • Delete the build folder and rebuild: rm -rf build/debug && Ctrl+Shift+B

Failed to start the listener for URL: wss://*:5568 (Address in use)

  • Make sure Motorcortex is not running: sudo motorcortex stop
  • Make sure no other instances of your-program-name is running

Building takes a long time

  • Make sure Motorcortex is not running: sudo motorcortex stop
  • Make sure no other instances of your-program-name is running

Installing Motorcortex Plugins

There are two CLion plugins that make developing Motorcortex applications easier: Motorcortex Templates and Motorcortex ToolChains.

Both can be installed in the plugin menu of Clion.

  1. In the Main Menu on the top left corner open: File → Settings, then find the Plugins menu.

  2. In the plugins menu search for Motorcortex.

  3. Install both Motorcortex Templates and Motorcortex ToolChains plugins

  4. Press restart IDE -> press Restart.

    image not found

Creating a New Motorcortex Project

Using the Motorcortex Templates plugin you can create a new Motorcortex project directly from CLion. This will setup a basic Motorcortex project structure for you with all necessary files. You an then easily develop, build and deploy your application from within CLion.

  1. In the Main Menu on the top left corner open: File → New Project.

  2. In the new project menu select C++ Motorcortex on the left side.

  3. Fill in the Location and select the options you want.

  4. Press Create.

    image not found

Setup-up Toolchains

There are two ways of building Motorcortex Control applications:

  • Cross-Remote: A hybrid between cross-platform development and remote development. It will build the code on your local machine and run/debugs on the target machine.
  • Remote: Builds and runs/debugs on the target machine.

In Clion you can setup different toolchains to build your Motorcortex applications. Using the Motorcortex ToolChains plugin you can easily setup the toolchains needed for cross-remote development.

Install Motorcortex SDK

  1. From the Motorcortex store download the latest Motorcortex SDK for your system, for example mcx-rtos-glibc-x86_64-mcx-image-dev-corei7-64-mcx-intel-toolchain-2025.03-0-g0e9d0e9.sh.

  2. Give the file execution permissions: (Replace the filename with the one you downloaded)

    chmod +x mcx-rtos-glibc-x86_64-mcx-image-dev-corei7-64-mcx-intel-toolchain-2025.03-0-g0e9d0e9.sh
    
  3. Run the installer: (Replace the filename with the one you downloaded)

    ./mcx-rtos-glibc-x86_64-mcx-image-dev-corei7-64-mcx-intel-toolchain-2025.03-0-g0e9d0e9.sh
    
  4. Follow the instructions on screen to complete the installation. Make sure to remember the installation path, you will need it in the next step.

Make sure to install the SDK that matches your Motorcortex controller version. You can check your controller version by running cat /etc/issue on the controller terminal.

System Toolchain

  1. In the Main Menu on the top left corner open: File → Settings, then find the Build, Execution, Deployment → Toolchains menu.
  2. Add a new toolchain by pressing the button and select system.
  3. Rename it to motorcortex! (Do not give it another nam and this is case-sensitive)
  4. Add environment by pressing Add environment and selecting from file. In the Environment file path enter the path to the mcx-clion-environment.sh file in the Motorcortex SDK installation directory.
    image not found
  5. Change the build tool to make if it is not already selected. (Ninja is supported but it will give a warning in the CMake window which can be ignored)
  6. Press Apply to save the toolchain settings.
    image not found
  7. Remove the default toolchain or move it below the motorcortex toolchain to make sure the Motorcortex toolchain is used by default.

Remote Host

For this step, make sure you are connected to your Motorcortex controller via Ethernet. See Connecting to your Motorcortex Controller for more information.

  1. In the Main Menu open File → Settings under Build, Execution, Deployment you will find the Toolchains menu.

  2. Add a new toolchain by pressing the button and select Remote Host.

  3. In the Credentials: press the button to enter the SSH Configurations menu. Add a new configuration by pressing the button and fill in the following data:

    • Host: 192.168.2.100 or the IP address of your Motorcortex controller if you changed it.
    • Port: 22
    • User name: admin or your custom username if you changed it.
    • Password: vectioneer or your custom password if you changed it.
  4. Press the Test Connection button to make sure your connection is OK. If not, re-check your controller connection.

  5. If the connection is good you can press OK to close the SSH Configurations menu.

  6. Wait for Cmake and the C/C++ Compiler to be detected:

    • CMake: Remote host CMake
    • Build Tool: Default, Detected: make
    • C Compiler: Default, Detected: cc
    • C++ Compiler: Default, Detected: c++
    • Debugger:Remote Host GDB
  7. Press the Apply button to save the Toolchain settings.

image not found

Run/Debug Configurations

To easily build and run your Motorcortex application from within CLion you can setup Run/Debug configurations for both cross-compiling and remote development. With the Motorcortex ToolChains plugin this is also made easy.

  1. In the top bar select and select configuration edit....

    image not found

  2. Press the button to add a new configuration and select Motorcortex Remote Application.

  3. You can name the configuration as you like, for example mcx-example.

  4. In the Program arguments field add the following:

    -s -c /etc/motorcortex/config/config.json
    
  5. Make sure that the Deployment profile automatically selected Remote Host ($ID$) as the option, with $ID$ being the ID of your remote host toolchain.

    If you cannot see Remote Host for your IP, see the instructions below.

  6. Press Apply to save the configuration.

image not found

When you pressed apply it should have automatically created two new folders in your project directory: cmake-build-crossdebug and cmake-build-crossrelease. In the Cmake window of Clion a warning might appear but this can be ignored:

CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_VERBOSE_MAKEFILE

Create new Deployment profile

  1. In the Main Menu open Tools → Deployment and click on configurations....
  2. Add a new SFTP and enter the prefered name, for example Remote Host.
  3. Add the SSH configuration that you use to connect to the target machine.
  4. Select Use rsync for download/upload/sync. (This will make it faster)
  5. Press OK.
  6. You should now be able to use the Remote Host in the Run/Debug Configurations menu

Using the Toolchains

Compiling and Debugging/Running

  1. In the top right corner of CLion select the Run/Debug Configuration you created earlier, for example mcx-example.
  2. To build the application press the button.
  3. To run or debug the application press the or button.

Installing and Running your Application Remotely

  1. In control/MainControlLoop.cpp, change the current iterateOp function to the following code:

       bool MainControlLoop::iterateOp_(const container::TaskTime &systemTime, container::UserTime *userTime) {
          log_info("Test");
    
          return true;
       }
    
  2. In CLion set your Run/Debug Configuration to Remote Host.

  3. Press Install (Located under build in the top bar). This will install the application on the Motorcortex controller.

  4. After installation is complete, open a terminal, either in CLion or your system terminal.

  5. Run the following command to ssh into the the Motorcortex controller: (Update the Username and IP address if needed)

    ssh admin@192.168.2.100
    
  6. Once logged in, run the following command to restart the Motorcortex application:

    sudo motorcortex restart
    
  7. Run the following command to view the output logs:

    mcx-lastlog
    
  8. You should see the Test log message appearing every control loop iteration.

For more information on control application development, please refer to the Developing Control Applications section of the documentation.

Common issues

If you encounter issues while setting up or using the Motorcortex toolchains in CLion, here are some common problems and their solutions:

  • fatal error: mcx/core.h: No such file or directory: This error indicates that the Motorcortex SDK is not properly configured in the toolchain. Make sure you have the motorcortex toolchain as the top priority toolchain and that the environment file path is correctly set to the mcx-clion-environment.sh file in the Motorcortex SDK installation directory. Remove the Default toolchain if necessary or move it below the motorcortex toolchain. Remove the cmake-build directories and press Reload CMake Project in CLion.

  • Removing Cmake-build directories: If you encounter build issues, try removing the cmake-build-crossdebug and cmake-build-crossrelease directories in your project folder. This will force CLion to regenerate the build files and can resolve various build-related problems.


  1. In the Main Menu open File → Settings under Build, Execution, Deployment you will find the Toolchains menu.

  2. Add a new toolchain by pressing the button and select Remote Host.

    image not found
  3. In the Credentials: press the button to enter the SSH Configurations menu. Add a new configuration by pressing the button and fill in the following data:

    • Host: 192.168.2.100
    • Port: 22
    • User name: admin
    • Password: vectioneer
  4. Press the Test Connection button to make sure your connection is OK. If not, re-check your controller connection.

  5. If the connection is good you can press OK to close the SSH Configurations menu.

  6. Wait for Cmake and the C/C++ Compiler to be detected:

    • CMake: Remote host CMake
    • Build Tool: Default, Detected: make
    • C Compiler: Default, Detected: cc
    • C++ Compiler: Default, Detected: c++
    • Debugger:Remote Host GDB

    Press the Apply button to save the Toolchain settings.

  7. Under Build, Execution, Deployment open the Cmake menu, set ToolChain, to Remote Host with dropdown function. Set other parameters to (default):

    • Build type: Debug
    • Generator: Use default Unix Makefiles
    • Cmake options: -G "CodeBlocks - Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug
    • Build directory: cmake-build-debug-remote-host
    • Build options: -- -j 9
    image not found
  8. Press the OK button to save the CMake settings and close the Settings window.

  9. Wait for a couple of seconds while remote and local systems are synchronized.

  10. Make sure that your controller is not running a Motorcortex application. Open the Terminal in CLion and run the following command:

ssh admin@192.168.2.100
sudo motorcortex stop
  1. In CLion set your Run/Debug Configuration to Debug-Remote Host.

    image not found
  2. Press play to build and run the application.

  3. To compile code with the latest modifications press Rebuild Project.

    image not found
  4. Congratulations you are now ready to start remote developing your Motorcortex application.