Building the code with WSL

Hi!
I’m trying to build the code with WSL2 (Windows Subsystem for Linux) and waf. I’m following the wiki and this post:


Thanks a lot @Eosbandi! That was a great help.
I also looked at the steps in this video:


Unfortunately I still get an error when I’m trying to configure the board type:
root@Felix-HauptPC:/home/ardupilot# ./waf configure --board CubeBlack
Setting top to                           : /home/ardupilot
Setting out to                           : /home/ardupilot/build
Autoconfiguration                        : enabled
Setting board to                         : CubeBlack
Using toolchain                          : arm-none-eabi
Checking for 'g++' (C++ compiler)        : /usr/bin/arm-none-eabi-g++
Checking for 'gcc' (C compiler)          : /usr/bin/arm-none-eabi-gcc
Checking for c flags '-MMD'              : yes
Checking for cxx flags '-MMD'            : yes
Checking for program 'make'              : /usr/bin/make
Checking for program 'arm-none-eabi-objcopy' : /usr/bin/arm-none-eabi-objcopy
Including /home/ardupilot/libraries/AP_HAL_ChibiOS/hwdef/fmuv3/hwdef.dat
Adding environment OPTIMIZE -O2
Removing PB0
Removing PB1
Removing PA8
Removing PE3
Setup for MCU STM32F427xx
Writing hwdef setup in /home/ardupilot/build/CubeBlack/hwdef.h
Writing DMA map
Generating ldscript.ld
Default parameters path from hwdef: /home/ardupilot/libraries/AP_HAL_ChibiOS/hwdef/CubeBlack/defaults.parm
Checking for env.py
env set OPTIMIZE=-O2
env set HAL_WITH_UAVCAN=1
env set PROCESS_STACK=0x2000
env set MAIN_STACK=0x400
env set IOMCU_FW=0
env set PERIPH_FW=0
env set BOARD_FLASH_SIZE=2048
env set CPU_FLAGS=['-mcpu=cortex-m4', '-mfpu=fpv4-sp-d16', '-mfloat-abi=hard', '-DARM_MATH_CM4', '-u_printf_float']
env set CORTEX=cortex-m4
env set APJ_BOARD_ID=9
env set APJ_BOARD_TYPE=STM32F427xx
env set USBID=0x2dae/0x1011
env set FLASH_RESERVE_START_KB=16
env set DEFAULT_PARAMETERS=/home/ardupilot/libraries/AP_HAL_ChibiOS/hwdef/CubeBlack/defaults.parm
env set CHIBIOS_BUILD_FLAGS=USE_FATFS=yes CHIBIOS_STARTUP_MK=os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f4xx.mk CHIBIOS_PLATFORM_MK=os/hal/ports/STM32/STM32F4xx/platform.mk MCU=cortex-m4 ENV_UDEFS=-DCHPRINTF_USE_FLOAT=1
Traceback (most recent call last):
  File "/home/ardupilot/modules/waf/waflib/Scripting.py", line 158, in waf_entry_point
    run_commands()
  File "/home/ardupilot/modules/waf/waflib/Scripting.py", line 251, in run_commands
    ctx = run_command(cmd_name)
  File "/home/ardupilot/modules/waf/waflib/Scripting.py", line 235, in run_command
    ctx.execute()
  File "/home/ardupilot/modules/waf/waflib/Configure.py", line 159, in execute
    super(ConfigurationContext, self).execute()
  File "/home/ardupilot/modules/waf/waflib/Context.py", line 204, in execute
    self.recurse([os.path.dirname(g_module.root_path)])
  File "/home/ardupilot/modules/waf/waflib/Context.py", line 286, in recurse
    user_function(self)
  File "/home/ardupilot/wscript", line 279, in configure
    cfg.get_board().configure(cfg)
  File "Tools/ardupilotwaf/boards.py", line 44, in configure
    self.configure_env(cfg, env)
  File "Tools/ardupilotwaf/boards.py", line 477, in configure_env
    cfg.load('chibios')
  File "/home/ardupilot/modules/waf/waflib/Configure.py", line 270, in load
    func(self)
  File "Tools/ardupilotwaf/chibios.py", line 363, in configure
    setup_can_build(cfg)
  File "Tools/ardupilotwaf/chibios.py", line 263, in setup_can_build
    cfg.srcnode.find_dir('modules/uavcan/libuavcan/include').abspath(),
AttributeError: 'NoneType' object has no attribute 'abspath'

What am I doing wrong? I’d appreciate any help.

are your submodules upto date?

https://ardupilot.org/dev/docs/git-submodules.html

git submodule init
git submodule update --recursive

2 Likes

Thanks a lot, Peter! That was surprisingly easy. That did the trick! I tried “git submodule init” and “git submodule refresh --recursive” before, but that wasn’t the right thing to do as it seems.

After that I could configure the board, but still couldn’t compile the code, because I ran into the exact same error described here:

pip intall future didn’t work, as it is no longer supported, but the solution was to type in
pip3 install future
Just in case anyone else has the same problem.

Unfortunately I’m still left with an error which looks like that:

root@Felix-HauptPC:/home/ardupilot# ./waf heli
Waf: Entering directory `/home/ardupilot/build/CubeBlack'
Checking for env.py
env added OPTIMIZE=-O2
env added HAL_WITH_UAVCAN=1
env added PROCESS_STACK=0x2000
env added MAIN_STACK=0x400
env added IOMCU_FW=0
env added PERIPH_FW=0
env added BOARD_FLASH_SIZE=2048
env appended CPU_FLAGS=['-mcpu=cortex-m4', '-mfpu=fpv4-sp-d16', '-mfloat-abi=hard', '-DARM_MATH_CM4', '-u_printf_float']
env added CORTEX=cortex-m4
env added APJ_BOARD_ID=9
env added APJ_BOARD_TYPE=STM32F427xx
env added USBID=0x2dae/0x1011
env added FLASH_RESERVE_START_KB=16
env added DEFAULT_PARAMETERS=/home/ardupilot/libraries/AP_HAL_ChibiOS/hwdef/CubeBlack/defaults.parm
env added CHIBIOS_BUILD_FLAGS=USE_FATFS=yes CHIBIOS_STARTUP_MK=os/common/startup/ARMCMx/compilers/GCC/mk/startup_stm32f4xx.mk CHIBIOS_PLATFORM_MK=os/hal/ports/STM32/STM32F4xx/platform.mk MCU=cortex-m4 ENV_UDEFS=-DCHPRINTF_USE_FLOAT=1
Padded 24 bytes for bootloader.bin to 16288
Embedding file bootloader.bin:/home/ardupilot/Tools/bootloaders/CubeBlack_bl.bin
Embedding file hwdef.dat:/home/ardupilot/build/CubeBlack/hw.dat
Embedding file io_firmware.bin:Tools/IO_Firmware/iofirmware_lowpolh.bin
[ 8/10] Processing uavcangen: libraries/AP_UAVCAN/dsdl/ardupilot libraries/AP_UAVCAN/dsdl/com
Traceback (most recent call last):
  File "/home/ardupilot/modules/uavcan/libuavcan/dsdl_compiler/libuavcan_dsdlc", line 59, in <module>
    from libuavcan_dsdl_compiler import run as dsdlc_run
  File "/home/ardupilot/modules/uavcan/libuavcan/dsdl_compiler/libuavcan_dsdl_compiler/__init__.py", line 18, in <module>

    from uavcan import dsdl
ModuleNotFoundError: No module named 'uavcan'
uavcangen returned 1 error code
Waf: Leaving directory `/home/ardupilot/build/CubeBlack'
Build failed
 -> task in 'uavcan' failed (exit status 1):
        {task 139630297795040: uavcangen ardupilot,com -> }
 (run with -v to display more information)

Seems like that uavcan-module is missing… How can I install that?

I managed to solve the problem. For everyone else who is trying to compile the code with WSL on Windows 10: Here is a detailed description of what I did. If you follow my manual step by step, everything should work just fine. I tried that with Ubuntu 18.04 LTS and the latest Ubuntu version. Both with WSL 2, but it should work with WSL 1 too, I guess.

  • install Ubuntu from the microsoft store (if possible, activate WSL 2 first)
  • start it up and enter a username
  • enter a password
  • sudo passwd root
  • enter new password
  • su root
  • cd ..
  • apt-get update
  • apt-get upgrade
  • git clone https://github.com/ardupilot/ardupilot.git
  • cd ardupilot
  • git submodule init
  • git submodule update --recursive
  • cd Tools/environment_install
  • su username (fill in your username to unroot)
  • ./install-prereqs-ubuntu.sh
  • no need to remove gcc-arm-none-eabi…/bin or any other files
  • apt-get install gcc-arm-none-eabi
  • go up to ardupilot directory
  • su root
  • pip3 install future
  • git submodule update --init --recursive
  • ./waf list_boards
  • ./waf configure --board CubeBlack
    (or whatever board you are using)
  • ./waf heli
    (or the vehicle type you are using. You can also type ./waf copter ./waf plane etc.)

If you want to use the stable branch instead of master, type:

  • git checkout ArduCopter-stable
  • ./waf distclean
2 Likes

Hi, so using WSL 2 with Ubuntu-20.04 I get a failure at the ‘./install-prereqs-ubuntu.sh’ point:

> Package python-matplotlib is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package python-scipy is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package python-empy is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Unable to locate package python-pip
E: Package 'python-matplotlib' has no installation candidate
E: Unable to locate package python-serial
E: Package 'python-scipy' has no installation candidate
E: Unable to locate package python-opencv
E: Package 'python-empy' has no installation candidate

Seems like some repositories are not available for 20.04.

Using Ubuntu-18.04 it works fine if I clone into /home. However, if I clone the repo under /mnt/c/ so I can access the files from Windows, I get some errors:

Traceback (most recent call last):
File “/mnt/c/Clones/ardupilot/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py”, line 2052, in
copy_common_linkerscript(outdir, args.hwdef)
File “/mnt/c/Clones/ardupilot/libraries/AP_HAL_ChibiOS/hwdef/scripts/chibios_hwdef.py”, line 839, in copy_common_linkerscript
os.path.join(outdir, “common.ld”))
File “/usr/lib/python2.7/shutil.py”, line 140, in copy
copymode(src, dst)
File “/usr/lib/python2.7/shutil.py”, line 105, in copymode
os.chmod(dst, mode)
OSError: [Errno 1] Operation not permitted: ‘/mnt/c/Clones/ardupilot/build/MatekF405/common.ld’
Failed to process hwdef.dat ret=1
(complete log in /mnt/c/Clones/ardupilot/build/config.log)

Hopefully this info helps someone out.

Thanks, Ian

hi, sorry for bothering. so you fix the problem by these steps?

Yes, for me it’s working with the steps above. Just checked again with Ubuntu 20.04.3 LTS and WSL2.

1 Like

yes, it works. tks a lot.[quote=“Felix, post:7, topic:60377, full:true”]
Yes, for me it’s working with the steps above. Just checked again with Ubuntu 20.04.3 LTS and WSL2.
[/quote]

That’s great! You’re welcome :slight_smile: