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

조회 수: 97 (최근 30일)
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.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2021년 9월 27일
"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
Michael
Michael 2022년 5월 18일
편집: Michael 2022년 6월 28일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Specialized Messages에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by