MATLAB Answers

Why do I get the error "Could not find CMake in your system" when using "rosgenmsg"?

49 views (last 30 days)
MathWorks Support Team
MathWorks Support Team on 27 Sep 2021 at 4:00
Commented: Xin Xing on 29 Sep 2021 at 16:51
I am using the 'rosgenmsg' function from ROS Toolbox with MATLAB R2020b. Although I have CMake installed on my system, I get the following error message:
Error using ros.internal.utilities.getCMakeBinaryPath (line 19)
Could not find CMake in your system. Please install CMake version 3.15.5
or higher and rerun the command.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Sep 2021 at 4:00
"rosgenmsg" and "ros2genmsg" depend on the system being able to find the CMake executable. So if the command
>> system('cmake --version')
does not work from within MATLAB, then "rosgenmsg" won't be able to find it either.
On Windows, you may see the following error:
>> system('cmake --version');
'cmake' is not recognized as an internal or external command, 
operable program or batch file.
On Mac, you may see the following error:
>> system('cmake --version’);
zsh:1: command not found: cmake
Typically, as part of the CMake installation workflow, the CMake executable folder gets added to the PATH environment variable. Note that this is not the root CMake application directory, but the directory that contains the CMake executable. The folder to add to the path may be 'C:\Program Files\CMake\bin' on Windows and '/Applications/' on Mac.
You can test this within MATLAB easily:
>> oldPath = getenv('PATH');
>> newPath = strcat(oldPath, pathsep, 'C:\Program Files\CMake\bin'); % on Windows
% >> newPath = strcat(oldPath, pathsep, '/Applications/'); % on Mac
>> setenv('PATH', newPath);
>> system('cmake --version')
% Then try rosgenmsg
If that works, we suggest permanently adding that folder to the PATH environment variable, or if you don't want to do that, creating a startup.m file that does the environment manipulation above.

More Answers (0)


No tags entered yet.




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!