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

101 visualizaciones (últimos 30 días)
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.

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 27 de Sept. de 2021
"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/CMake.app/Contents/bin' 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/CMake.app/Contents/bin'); % 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.
  1 comentario
Michael
Michael el 18 de Mayo de 2022
Editada: Michael el 28 de Jun. de 2022
For anyone who wants to add this path permanently, do the following.
1. Create a 'startup.m' file by typing the following the command window:
edit(fullfile(userpath,'startup.m'))
If you don't yet have a startup.m file, it will prompt you to ask if you'd like to make one. Select 'yes.'
2. Then in the the startup.m script editor, add the following:
%To add CMake Directory to PATH
%Based on answer from https://www.mathworks.com/matlabcentral/answers/1461834-why-do-i-get-the-error-could-not-find-cmake-in-your-system-when-using-rosgenmsg
oldPath = getenv('PATH');
%newPath = strcat(oldPath, pathsep, 'C:\Program Files\CMake\bin'); % on Windows
newPath = strcat(oldPath, pathsep, '/Applications/CMake.app/Contents/bin'); % on Mac
setenv('PATH', newPath);
%system('cmake --version')
UPDATE: If you installed Cmake with brew on a Mac, the path should be usr/local/bin/. i.e.
newPath = strcat(oldPath, pathsep, 'usr/local/bin/'); % on Mac
3. Save and close the file. Quit and restart Matlab.
4. Check that the PATH variable has been set properly by 'startup.m'
>> getenv('PATH')
ans =
'/usr/bin:/bin:/usr/sbin:/sbin:/Applications/CMake.app/Contents/bin'
We can see that CMake is now part of the PATH variable.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Specialized Messages en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by