matlab 2020b rosgenmsg can't find CMake?

Hello,
I used rosgenmsg for ROS1 with Matlab 2020a on Ubuntu 18.04 and it worked fine. Now I'm trying the same command on Matlab 2020b on Ubuntu 20.04. It seems there's a whole new build system using Python and a C++ compiler in the backend instead of Java. I now get an error about CMake not found:
Validating message files in folder '/home/anton/catkin_ws/src/crtk'..Done.
[0/1] Generating MATLAB interfaces for custom message packages... 0%Error using ros.internal.utilities.getCMakeBinaryPath (line 24)
Could not find CMake in your system. Please install CMake version 3.15.5 or higher and rerun the command.
Error in ros.internal.CatkinBuilder.getCMakePath (line 82)
[aPath, aVersion] =
ros.internal.utilities.getCMakeBinaryPath(ros.internal.CatkinBuilder.CMAKEMINVERSION);
Meawhile, CMake is installed (using apt):
~$ cmake --version
cmake version 3.16.3
CMake suite maintained and supported by Kitware (kitware.com/cmake).
~$ which cmake
/usr/bin/cmake
Any advice on how to proceed to fix this issue? Also, I'm interested in ROS 1 messages (Noetic), not ROS 2.

 Accepted Answer

Hello Anton,
R2020b involved a large replacement of the ROS functionality in MATLAB. As you have found, it supports rosgenmsg natively in the toolbox (no support package required), but does have new dependencies on Python and CMake.
In order to ensure that CMake is available in MATLAB, ensure that it is on the system PATH environment variable. Based on your terminal commands, it seems like it should be. Just to make sure, can you run these from within MATLAB:
!which cmake
!cmake --version
It's possible that the PATH in your terminal and the PATH in the MATLAB environment is different for some reason.
For other requirements (Python, compiler), see the ROS Toolbox System Requirements page.
-Cam

13 Comments

Hello,
Using ! to start a shell command was a useful starting point. It seems cmake is found properly but not the runtime libraries for CMake, hence the error. Here is how I solved my problem:
>> !which cmake
/usr/bin/cmake
So far so good, but:
>> !cmake --version
cmake: /usr/local/MATLAB/R2020b/bin/glnxa64/libcurl.so.4: no version information available (required by cmake)
cmake: /usr/local/MATLAB/R2020b/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by cmake)
cmake: /usr/local/MATLAB/R2020b/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by /usr/lib/x86_64-linux-gnu/libjsoncpp.so.1)
I did a bit of reading online and found the following "fix". The path for libstdc++.so.6 might be Ubuntu 20.04 specific. In a shell:
export LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libstdc++.so.6"
matlab
In matlab, I was then able to generate the custom messages. To make sure the newly generated code was not dependent on the Ubuntu libstdc++.so.6, I saved the path as suggested:
edit(fullfile(userpath,'startup.m'))
In my startup.m I added:
addpath('/home/anton/catkin_ws/src/crtk/matlab_msg_gen_ros1/glnxa64/install/m')
Then I exited Matlab, restarted it in a new shell to make sure LD_PRELOAD was not defined and tested with:
which startup
% show message properties
rosmsg('show', 'crtk_msgs/operating_state')
% create a message
m = rosmessage('crtk_msgs/operating_state')
And that worked fine.
I'm glad to hear you got it working. Thanks for providing so much detail on your solution!
-Cam
I have a similar error when use rosgenmsg.
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.
Platform: MATLAB 2020b on MacOS Catalina.
And while in OS' bash shell run
which make
Output:
/usr/local/bin/cmake
Then run
cmake --version
Output:
cmake version 3.18.4
CMake suite maintained and supported by Kitware (kitware.com/cmake).
In Matlab Shell run:
!which make
It output nothing.
Eventhough I did the following (not quite sure if it is the right way)
setenv('PATH', [getenv('PATH') ';/usr/local/bin'])
It does not help with the case.
Any suggestion with this case please?
We're looking for the "cmake" executable, not "make", so be sure that you are searching for that. Then add the containing directory of that executable to your path.
If you are adding it to the back of the path, it is possible that you have an earlier version of CMake towards the front of the path, so you would still see an error. It's recommended that you ensure only one cmake executable is on-path, or put the correct version at the head.
Also, the semi-colon is only used as the path separator on Windows - Unix uses a colon. I recommend using pathsep for general purposes.
setenv('PATH', strcat('/usr/local/bin', pathsep, getenv('PATH')))
Hello,
I'm having the same problem using rosgenmsg with Matlab 2020b on Ubuntu 16.04.
I have followed the discussion and checked the path. Here's what I got from the shell:
~$ which cmake
/usr/bin/cmake
~$ cmake --version
cmake version 3.5.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
Here's what I got from Matlab:
>> !which cmake
/usr/bin/cmake
>> !cmake --version
cmake: /usr/local/MATLAB/R2020b/bin/glnxa64/libcurl.so.4: no version information available (required by cmake)
cmake version 3.5.1
I have tried the proposed solution, however it didn't work for me.
Do you have any suggestions?
Thanks in advance!
You have tried running this prior to running the system commands in MATLAB?
setenv('PATH', strcat('/usr/local/bin', pathsep, getenv('PATH')))
Or you tried with your path to cmake?
setenv('PATH', strcat('/usr/bin', pathsep, getenv('PATH')))
Or you tried this solution?
export LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libstdc++.so.6"
matlab
Make sure that your CMake executable is where you think it is. It is possible that your system thinks it is usr/bin/cmake, when it is actually in usr/local/bin/cmake.
Also, ROS Toolbox requires CMake version 3.15.5 or greater, so I would recommend updating CMake anyway.
I tried this solution but when I run
!cmake --version
I no longer get the libstdc++ error, but I get:
cmake: /usr/local/MATLAB/R2021a/bin/glnxa64/libcurl.so.4: version `CURL_OPENSSL_4' not found (required by cmake)
How can I fix this? Is there a for it to get the libraries without running the export command every time?
After preloading libstdc library the GLIBCXX errors are fixed but I'm still getting the same error as Friderico. In system bash shell cmake works normally.
Whitin MATLAB I get
cmake: /usr/local/MATLAB/R2021a/bin/glnxa64/libcurl.so.4: version `CURL_OPENSSL_4' not found (required by cmake)
when running
!cmake --version
Could it be that libcurl shipped with MATLAB is not using openssl?
On my system (KDE neon/Ubuntu 20.04) I can install libcurl4-openssl-dev, libcurl4-nss-dev or libcurl4-gnutls-dev. System shipped CMake seems to be built against the opensssl version of curl.
in my case the solution is preloading system's libcurl as well:
export LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libstdc++.so.6:/usr/lib/x86_64-linux-gnu/libcurl.so"
Hello,
today i have installed MATLAB R2021b. Before I used the preview version of R2021b and had no problems for rosgenmsg(), wenn Cmake 3.21.1 had installed. But now I have same problem, even though i have intalled Cmake 3.21.1, 3.21.3 or 3.20.6. I was warned, that MATLAB could not find Cmake in my system. Has anyone ideas?
Ensure that the CMake executable installation location is on the PATH environment variable. See if you can run this inside of MATLAB:
!cmake --version
Hello,
I, too, ran into the same problems desribed here with the difference of me having it installed on Windows. I tried most of the stuff mentioned here, but nothing worked so far. I added cmake to path while installing it. I added it to the matlab path via the GUI provided. I work with the Matlab Version 2021b.
The following commands (in Matlab) give the following results back:
  • "which cmake" gives me: "'CMake' not found."
  • !which command doesnt exist
  • "!cmake --version" gives me:
"cmake version 3.22.0-rc1
CMake suite maintained and supported by Kitware (kitware.com/cmake)."
I test if it's working by running ("Monitor & Tune" - Button) in the Simulink basic example called "robotROSConnectToRobotExample". After a while it says:
"Could not find CMake in your system. Please install CMake version 3.15.5 or higher and rerun the command.
Caused by: Validation error(s): Could not find CMake in your system. Please install CMake version 3.15.5 or higher and rerun the command."
Could anyone help me with this?
I am running into the same error. In Windows:
>> !where cmake
returns C:\Program Files\CMake\bin\cmake.exe
The version returned is the same as yours (3.22.0-rc1), so better than 3.15.5.
I found getCMakeBinaryPath.m at C:\Program Files\MATLAB\R2021b\toolbox\ros\utilities\+ros\+internal\+utilities\getCMakeBinaryPath.m and inspected it. The line that gave me trouble is:
[status, result] = system('env LD_LIBRARY_PATH= cmake --version');
I edited the file with admin rights and changed it to:
[status, result] = system('cmake --version');
I restarted Matlab and it worked. On Linux, "env" exists, so it won't return an error, and it actually returns the cmake version to parse. But on Windows, "env" doesn't exist, so the call returns an error. Honestly, the system call in the released file looks broken. Copy/paste error. Perhaps no regression testing on Windows for this file?
Ugh! OK, I have a MUCH simpler answer: It's fixed in 2021b Update 2. :-D
Not enough coffee this morning. It's a nice fix as well. Much better than my hack.
Need to get to sleep earlier.

Sign in to comment.

More Answers (2)

I had to use a different solution since the above solution did not solve the problem for me. I am using Matlab R2021a and Ubuntu 18.
Running:
!cmake --version
in MATLAB command window produced the follwing error:
cmake: /usr/local/MATLAB/R2021a/bin/glnxa64/libcurl.so.4: version `CURL_OPENSSL_4' not found (required by cmake)
This is what worked for me:
It seems that the installed cmake version for Ubuntu 18 is v3.10, but Matlab needs version v3.15+ for ROS Toolbox.
Therefore I downloaded version 3.20 from https://cmake.org/download/ and installed it using this answer (NB: without removing the previous cmake).
Remember to add the export lines to your .bashrc
I could then succesfully run:
folderpath = fullfile('~/catkin_ws/src/mavros')
rosgenmsg(folderpath)
to build mavros_msg

2 Comments

I'm sorry, this didn't work for me. I followed the same procedure you mentioned, but when I run
!which cmake
I still get
/usr/bin/cmake
Then, if I run
!cmake --version
I obtain the same output as before:
cmake: /usr/local/MATLAB/R2021a/bin/glnxa64/libcurl.so.4: version `CURL_OPENSSL_4' not found (required by cmake)
Instead, when I run the same commands on the Linux terminal, I get the right path:
/home/<user>/cmake-install/bin/cmake
and the right version I installed:
cmake version 3.21.0
I also added the "export" lines in ".bashrc".
Anyone got the same error and solved?
Hello Vincenzo,
I am having the same exact issue as you. Have you found a solution?

Sign in to comment.

Neel Bhatt
Neel Bhatt on 24 Jul 2021
Edited: Neel Bhatt on 24 Jul 2021
Jakobus Louw's answer worked for me.
Note:
  • There should be a correction to the cmake version: all the 1.xx versions listed in the answer mean 3.xx - i.e. Matlab 2021a needs cmake version 3.15+ (not 1.15+), but overall the steps outlined in this answer are correct.
To summarize: you can follow the following steps:
  1. Download cmake 3.20.5 from https://cmake.org/download/
  2. Open a terminal and run the following
  3. cd ~/Downloads/cmake-3.20.5/ # or wherever you downloaded cmake
  4. ./bootstrap --prefix=$HOME/cmake-install
  5. make
  6. make install
  7. export PATH=$HOME/cmake-install/bin:$PATH
  8. export CMAKE_PREFIX_PATH=$HOME/cmake-install:$CMAKE_PREFIX_PATH
  9. matlab
  10. !cmake --version # Check cmake version: it should be 3.20.5
You can now generate custom messages. You may need to generate custom messages using:
folderpath = 'PATH_TO_YOUR_MESSAGE_PACKAGE'
rosgenmsg(folderpath)
% Follow the next steps that appear in the command window
% For instance, if you are using ROS1:
% Note you may not have permissions to run the following two commands
% which will lead to a warning. In this case, close MATLAB and in the
% same terminal (where you ran exports), run MATLAB with sudo access: sudo matlab
addpath('PATH_TO_YOUR_MESSAGE_PACKAGE/matlab_msg_gen_ros1/glnxa64/install/m')
savepath
clear classes
rehash toolboxcache
rosmsg list % Confirm you have your custom message show up

1 Comment

Thank you, I fixed this in Jacobus' answer to avoid confusion.

Sign in to comment.

Categories

Find more on Code Generation in Help Center and File Exchange

Products

Release

R2020b

Community Treasure Hunt

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

Start Hunting!