Error in building simulink code for PX4-V6x

24 views (last 30 days)
Thai Hoa
Thai Hoa on 8 Sep 2025 at 13:09
Commented: Umar on 11 Sep 2025 at 15:47
Dear everyone,
I am building Simulink code for PX4 6x. However I got this issue. Could you let me know the solution?
Error:Compilation failure for command /opt/gcc-arm-none-eabi-9-2020-q2-update/bin/arm-none-eabi-g++ -DCONFIG_ARCH_BOARD_PX4_FMU_V6X -D_SYS_CDEFS_H_ -D_SYS_REENT_H_ -D__CUSTOM_FILE_IO__ -D__PX4_NUTTX -D__STDC_FORMAT_MACROS -DMODULE_NAME=\\\"px4_simulink_app\\\" -DPX4_MAIN=px4_simulink_app_app_main -DMODEL=waypoint_following -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DMODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0 -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DTID01EQ=0 -DTERMFCN=1 -DONESTEPFCN=1 -DMAT_FILE=0 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0 -DPX4 -DFMUv6x -DNULL=0 -DMW_PX4_NUTTX_BUILD -DEXTMODE_DISABLETESTING -DEXTMODE_DISABLEPRINTF -DEXTMODE_DISABLE_ARGS_PROCESSING=1 -D__linux__ -DXCP_PLATFORM_LINUX_NO_PIE_SUPPORT -DSTACK_SIZE=64 -D__MW_TARGET_USE_HARDWARE_RESOURCES_H__ -DRT -mcpu=cortex-m7 -mthumb -mfpu=fpv5-d16 -mfloat-abi=hard -Os -DNDEBUG -g -fdata-sections -ffunction-sections -fomit-frame-pointer -fmerge-all-constants -fno-signed-zeros -fno-trapping-math -freciprocal-math -fno-math-errno -fno-strict-aliasing -fvisibility=hidden -include visibility.h -Wall -Wextra -Warray-bounds -Wcast-align -Wdisabled-optimization -Wdouble-promotion -Wfatal-errors -Wfloat-equal -Wformat-security -Winit-self -Wlogical-op -Wpointer-arith -Wshadow -Wuninitialized -Wunknown-pragmas -Wunused-variable -Wno-missing-field-initializers -Wno-missing-include-dirs -Wno-unused-parameter -fdiagnostics-color=always -Wno-stringop-truncation -fno-builtin-printf -fno-strength-reduce -Wformat=1 -Wunused-but-set-variable -Wno-format-truncation -fcheck-new -Wreorder -Wno-overloaded-virtual -fno-rtti -fno-exceptions -fno-sized-deallocation -fno-threadsafe-statics -nostdinc++ -Wframe-larger-than=2000 -fpermissive -Wno-narrowing -Wno-address-of-packed-member -Wno-cast-align -D__KERNEL__ -std=gnu++14 -I/home/thaibahoa2024/PX4-Autopilot/boards/px4/fmu-v6x/src -I/home/thaibahoa2024/PX4-Autopilot/platforms/nuttx/src/px4/common/include -I/home/thaibahoa2024/PX4-Autopilot/build/px4_fmu-v6x_multicopter -I/home/thaibahoa2024/PX4-Autopilot/build/px4_fmu-v6x_multicopter/src/lib -I/home/thaibahoa2024/PX4-Autopilot/platforms/nuttx/src/px4/stm/stm32h7/include -I/home/thaibahoa2024/PX4-Autopilot/platforms/common -I/home/thaibahoa2024/PX4-Autopilot/platforms/common/include -I/home/thaibahoa2024/PX4-Autopilot/src -I/home/thaibahoa2024/PX4-Autopilot/src/include -I/home/thaibahoa2024/PX4-Autopilot/src/lib -I/home/thaibahoa2024/PX4-Autopilot/src/lib/matrix -I/home/thaibahoa2024/PX4-Autopilot/src/modules -I/home/thaibahoa2024/PX4-Autopilot/platforms/nuttx/NuttX/nuttx/arch/arm/src/armv7-m -I/home/thaibahoa2024/PX4-Autopilot/platforms/nuttx/NuttX/nuttx/arch/arm/src/chip -I/home/thaibahoa2024/PX4-Autopilot/platforms/nuttx/NuttX/nuttx/arch/arm/src/common -I/home/thaibahoa2024/PX4-Autopilot/platforms/nuttx/NuttX/apps/include -I/home/thaibahoa2024/PX4-Autopilot/build/px4_fmu-v6x_multicopter/external/Install/include -I/home/thaibahoa2024/PX4-Autopilot/src/modules/px4_simulink_app -I/home/thaibahoa2024/PX4-Autopilot/src/modules/mavlink -I/home/thaibahoa2024/PX4-Autopilot/build/px4_fmu-v6x_multicopter/mavlink -I/home/thaibahoa2024/PX4-Autopilot/build/px4_fmu-v6x_multicopter/mavlink/common -I/home/thaibahoa2024/PX4-Autopilot/build/px4_fmu-v6x_multicopter/mavlink/uAvionix -isystem /home/thaibahoa2024/PX4-Autopilot/platforms/nuttx/NuttX/include/cxx -isystem /home/thaibahoa2024/PX4-Autopilot/platforms/nuttx/NuttX/nuttx/include/cxx -isystem /home/thaibahoa2024/PX4-Autopilot/platforms/nuttx/NuttX/nuttx/include -o src/modules/px4_simulink_app/CMakeFiles/modules__px4_simulink_app.dir/MW_ParameterRead.cpp.obj -c ../../src/modules/px4_simulink_app/MW_ParameterRead.cpp with error '\\wsl.localhost\ubuntu-22.04\home\thaibahoa2024\PX4-Autopilot\build\px4_fmu-v6x_multicopter' CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Windows directory. bash: line 1: /opt/gcc-arm-none-eabi-9-2020-q2-update/bin/arm-none-eabi-g++: No such file or directory

Accepted Answer

Umar
Umar on 9 Sep 2025 at 15:12

Hi @Thai Hoa,

Thank you for sharing your challenge regarding compilation of Simulink-generated code for the PX4 FMU V6X. Although I do not currently have direct access to Simulink myself, I have carefully analyzed your error logs alongside the MathWorks UAV Toolbox documentation and PX4 developer guides. Below I provide a structured analysis of your comments in chronological order, followed by a step-by-step corrective workflow that aligns with the official references.

1. Your Comment

I am building Simulink code for PX4 6x. However I got this issue… UNC paths are not supported. Defaulting to Windows directory. bash: line 1: /opt/gcc-arm-none-eabi-9-2020-q2-update/bin/arm-none-eabi-g++: No such file or directory.”

Analysis of Issues

1. UNC Path Limitation

  • The PX4 build system is being invoked from a UNC path (`\\wsl.localhost\ubuntu-22.04\…`).
  • WSL does not support UNC paths as valid working directories; this forces the shell to fall back to Windows defaults, breaking the toolchain call.

2. Missing ARM GCC Toolchain

  • The compiler `arm-none-eabi-g++` was not found at `/opt/gcc-arm-none-eabi-9-2020-q2-update/bin`. This indicates the GNU Arm Embedded toolchain is either not installed in WSL or not accessible at the expected location.

3. Workflow Context

  • Your Simulink model (`waypoint_following`) generates C++ code via Embedded Coder, integrates it as a PX4 module (`px4_simulink_app`), and relies on PX4’s CMake/NuttX build system. So, for this workflow to succeed, the PX4 build must run fully inside WSL, with the proper toolchain installed.

Corrective Workflow (Synthesized from MathWorks Documentation)

1. Run Build from a Native WSL Path

   cd /home/thaibahoa2024/PX4-Autopilot

Avoid UNC paths (`\\wsl.localhost\…`). Always invoke the PX4 build directly inside WSL.

2. Install the PX4 Toolchain in WSL

PX4 provides a setup script that installs the correct ARM GCC cross-compiler and dependencies:

   cd ~/PX4-Autopilot/Tools/setup
   bash ubuntu.sh

This will install the GNU Arm Embedded toolchain (e.g., GCC 9-2020-q2), Ninja, CMake, and required libraries.

3. Verify Toolchain Availability

   which arm-none-eabi-g++
   arm-none-eabi-g++ --version

Confirm that a valid path and version string are returned.

4. Configure Simulink PX4 Support Package

In Simulink (via the UAV Toolbox Support Package for PX4 Autopilots), set *Hardware Implementation → Target Hardware = Pixhawk PX4.

  • The support package will automatically locate the installed toolchain in WSL
  • if MATLAB is properly configured. [MathWorks – PX4 Support Package Overview]( https://. www.mathworks.com/help/uav/px4-spkg.html)

5. Generate and Integrate Code

   * Use Simulink Embedded Coder to generate C++ source.
   * The PX4 support package places generated code under `src/modules/
      px4_simulink_app/` within your PX4 workspace.
   * CMake automatically includes this module in the PX4 firmware build.

6. Rebuild PX4 Firmware with Your Module

   make px4_fmu-v6x_default

This command should now successfully compile your Simulink module alongside the PX4 firmware.

7. Flash Firmware to the Board (Optional)

     make px4_fmu-v6x_default upload

References

MathWorks UAV Toolbox Support Package for PX4 Autopilots [ https://www.mathworks.com/help/uav/px4-spkg.html ]

PX4 Developer Guide – Setting up the PX4 Toolchain in WSL2 [ https://docs.px4.io/main/en/dev%5C_setup/dev%5C_env%5C_windows%5C_wsl.html ]

MathWorks – Setup and Configuration for PX4 in WSL [ https://www.mathworks.com/help/uav/setup-and-configuration-px4.html ]

In summary, your build failure arises from two root causes:

1. Running PX4 compilation from an unsupported UNC path. 2. Lack of a properly installed ARM embedded toolchain in WSL.

By (a) running the build directly from native WSL paths, (b) installing the toolchain with PX4’s setup script, and (c) ensuring Simulink’s PX4 support package points to this toolchain, you should be able to compile and deploy your Simulink-generated PX4 application reliably.

Please let me know the outcome after you follow these steps.

More Answers (1)

Thai Hoa
Thai Hoa on 11 Sep 2025 at 11:39
Dear @Umar,
I deeply thanks for your helpful comment.
I would like to summarize what I solved.
  1. In Unbuntu (WSL)
  • Install dependencies PX4
sudo apt update
sudo apt install git python3-pip python3-empy python3-toml python3-numpy \
python3-yaml python3-dev python3-setuptools ninja-build \
exiftool build-essential cmake python3-jinja2 -y
  • Setup ARM GCC Toolchain
cd /opt
sudo wget https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2020q2/gcc-arm-none-eabi-9-2020-q2- update-x86_64-linux.tar.bz2
sudo tar -xjf gcc-arm-none-eabi-9-2020-q2-update-x86_64-linux.tar.bz2
sudo rm gcc-arm-none-eabi-9-2020-q2-update-x86_64-linux.tar.bz2
  • Adding path
export PATH=/opt/gcc-arm-none-eabi-9-2020-q2-update/bin:$PATH
  • Next
source ~/.bashrc
  • Check
arm-none-eabi-g++ --version
  • Rebuild
make px4_fmu-v6x_multicopter
2. When install UAV toolbox in MATLAB:
  • Selec
/home/your-path/PX4-Autopilot
Then, install the same as MATLAB steps.
I hope this solution can be helpful for those who will encounter this issue. Best wishes,
---
Thank you @Umar once again.
  1 Comment
Umar
Umar on 11 Sep 2025 at 15:47

Hi @Thai Hoa,

Thank you for the detailed follow-up! I'm glad to hear that the solution worked for you and that you were able to resolve the issues. Your summary of the steps you took is really helpful and will definitely be valuable for others facing the same challenge.

Wishing you the best with your PX4 development, and feel free to reach out if you encounter any more questions in the future!

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!