ROS2 compile a standalone node: undefined references to `std::__th​row_bad_ar​ray_new_le​ngth()'

조회 수: 11 (최근 30일)
Hi all,
I am trying to create a standalone node for ROS2 with a publisher (see schema below) and I am using the following tutorial to set up the model to generate the code:
but when I compile it, I obtain the following error
undefined reference to `std::__throw_bad_array_new_length()
and I don't find a way to fix (below the imag with the error). I also got the same error with the Simulink model used in the tutorial.
System info:
  • OS: Ubuntu 22.04 LTS
  • ROS2 version: Humble
  • gcc version: 11.4.0

채택된 답변

Josh Chen
Josh Chen 2024년 5월 17일
Hi Federico,
Thanks for providing the system information. This error seems to be a compiler incompatible issue.
In R2023b version of MATLAB/Simulink, some internal packages were built with gcc-10. Hence, when compiling the Simulink model with gcc-11, you may see undefined reference errors.
This issue was resolved in the upcoming R2024b version, which uses gcc-12 to build those packages.
As a workaround for R2023b, you could consider installing gcc-10 on your machine so that the entire project uses the same gcc version during build process.
Best,
Josh
  댓글 수: 1
federico ciresola
federico ciresola 2024년 5월 21일
Hi Josh Chen,
you were right, I changed the version of gcc on my system and I resolved the problem.
I leave here the small resume of how to change the version of gcc/g++ on Ubuntu 22.04 LTS:
# Install gcc-10 and g++--10
sudo apt install gcc-10
sudo apt install g++-10
# Remove all alternatives configuration
sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++
# Add alternatives configuration for gcc/g++ versions
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-10 10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 11
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-10 10
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 11
# Change the default gcc/g++ version
sudo update-alternatives --config gcc
sudo update-alternatives --config g++
# Check the gcc verion
gcc --version
# Add gCC/g++ configuration for colcon
echo "export CC=/usr/bin/gcc-10" >> ~/.bashrc
echo "export CXX=/usr/bin/g++-10" >> ~/.bashrc
source ~/.bashrc
#run matlab/simulink
and in simulink I went to ROS tab, I opened Hardware settings>code generation and in the label Language standard inside the Target selection I choose C++10 (ISO):

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by