CLion
8 minute read
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.
-
In the
Main Menuon the top left corner open:File → Settings, then find thePluginsmenu. -
In the plugins menu search for
Motorcortex. -
Install both
Motorcortex TemplatesandMotorcortex ToolChainsplugins -
Press
restart IDE-> pressRestart.
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.
-
In the
Main Menuon the top left corner open:File → New Project. -
In the new project menu select
C++ Motorcortexon the left side. -
Fill in the Location and select the options you want.
-
Press
Create.
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
-
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. -
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 -
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 -
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/issueon the controller terminal.
System Toolchain
- In the
Main Menuon the top left corner open:File → Settings, then find theBuild, Execution, Deployment → Toolchainsmenu. - Add a new toolchain by pressing the
button and selectsystem. - Rename it to
motorcortex! (Do not give it another nam and this is case-sensitive) - Add environment by pressing
Add environmentand selectingfrom file. In the Environment file path enter the path to themcx-clion-environment.shfile in the Motorcortex SDK installation directory.
- Change the build tool to
makeif it is not already selected. (Ninja is supported but it will give a warning in the CMake window which can be ignored) - Press
Applyto save the toolchain settings.
- Remove the default toolchain or move it below the
motorcortextoolchain 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.
-
In the
Main MenuopenFile → SettingsunderBuild, Execution, Deploymentyou will find theToolchainsmenu. -
Add a new toolchain by pressing the
button and selectRemote Host. -
In the
Credentials:press thebutton to enter theSSH Configurationsmenu. Add a new configuration by pressing thebutton and fill in the following data:- Host:
192.168.2.100or the IP address of your Motorcortex controller if you changed it. - Port:
22 - User name:
adminor your custom username if you changed it. - Password:
vectioneeror your custom password if you changed it.
- Host:
-
Press the
Test Connectionbutton to make sure your connection isOK. If not, re-check your controller connection. -
If the connection is good you can press
OKto close theSSH Configurationsmenu. -
Wait for
Cmakeand theC/C++ Compilerto 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
- CMake:
-
Press the
Applybutton to save theToolchainsettings.
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.
-
In the
top barselectand selectconfiguration edit....
-
Press the
button to add a new configuration and selectMotorcortex Remote Application. -
You can name the configuration as you like, for example
mcx-example. -
In the
Program argumentsfield add the following:-s -c /etc/motorcortex/config/config.json -
Make sure that the
Deployment profileautomatically selectedRemote 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.
-
Press
Applyto save the configuration.
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
- In the
Main MenuopenTools → Deploymentand click onconfigurations.... - Add a new
SFTPand enter the prefered name, for exampleRemote Host. - Add the
SSH configurationthat you use to connect to the target machine. - Select
Use rsync for download/upload/sync. (This will make it faster) - Press
OK. - You should now be able to use the Remote Host in the Run/Debug Configurations menu
Using the Toolchains
Compiling and Debugging/Running
- In the top right corner of CLion select the
Run/Debug Configurationyou created earlier, for examplemcx-example. - To build the application press the
button. - To run or debug the application press the
orbutton.
Installing and Running your Application Remotely
-
In
control/MainControlLoop.cpp, change the currentiterateOpfunction to the following code:bool MainControlLoop::iterateOp_(const container::TaskTime &systemTime, container::UserTime *userTime) { log_info("Test"); return true; } -
In
CLionset yourRun/Debug ConfigurationtoRemote Host. -
Press
Install(Located underbuildin the top bar). This will install the application on the Motorcortex controller. -
After installation is complete, open a terminal, either in CLion or your system terminal.
-
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 -
Once logged in, run the following command to restart the Motorcortex application:
sudo motorcortex restart -
Run the following command to view the output logs:
mcx-lastlog -
You should see the
Testlog 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
motorcortextoolchain as the top priority toolchain and that the environment file path is correctly set to themcx-clion-environment.shfile in the Motorcortex SDK installation directory. Remove theDefaulttoolchain if necessary or move it below themotorcortextoolchain. Remove the cmake-build directories and pressReload CMake Projectin CLion. -
Removing Cmake-build directories: If you encounter build issues, try removing the
cmake-build-crossdebugandcmake-build-crossreleasedirectories in your project folder. This will force CLion to regenerate the build files and can resolve various build-related problems.
-
In the
Main MenuopenFile → SettingsunderBuild, Execution, Deploymentyou will find theToolchainsmenu. -
Add a new toolchain by pressing the
button and selectRemote Host.
-
In the
Credentials:press thebutton to enter theSSH Configurationsmenu. Add a new configuration by pressing thebutton and fill in the following data:- Host:
192.168.2.100 - Port:
22 - User name:
admin - Password:
vectioneer
- Host:
-
Press the
Test Connectionbutton to make sure your connection isOK. If not, re-check your controller connection. -
If the connection is good you can press
OKto close theSSH Configurationsmenu. -
Wait for
Cmakeand theC/C++ Compilerto 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
Applybutton to save theToolchainsettings. - CMake:
-
Under
Build, Execution, Deploymentopen theCmakemenu, setToolChain, toRemote Hostwithdropdownfunction. 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
- Build type:
-
Press the
OKbutton to save theCMakesettings and close theSettingswindow. -
Wait for a couple of seconds while remote and local systems are synchronized.
-
Make sure that your controller is not running a Motorcortex application. Open the
TerminalinCLionand run the following command:
ssh admin@192.168.2.100
sudo motorcortex stop
-
In
CLionset yourRun/Debug ConfigurationtoDebug-Remote Host.
-
Press
playtobuildandrunthe application. -
To compile code with the latest modifications press
Rebuild Project.
-
Congratulations you are now ready to start remote developing your Motorcortex application.