Building ArduPilot on OSX with waf

Any help with building ArduPilot on OSX fro px4-v2?

Following build with Make on OSX

and then adding
brew install make alias waf="$PWD/modules/waf/waf-light" waf configure --board=px4-v2 waf --targets bin/arducopter-quad
the build failed building MAVLink :frowning:
Waf: Leaving directory `/Users/bonney/dev_src/ardupilot/build/px4-v2’
Build failed
-> task in ‘px4_msg_gen’ failed (exit status 2):
{task 4430014256: cmake_build_task -> }
[’/usr/local/bin/cmake’, ‘–build’, ‘/Users/bonney/dev_src/ardupilot/build/px4-v2/modules/PX4Firmware’, ‘–target’, ‘msg_gen’]

Output from war

bonney@MacVan:ardupilot (master)$ waf configure --board=px4-v2
Setting top to                           : /Users/bonney/dev_src/ardupilot 
Setting out to                           : /Users/bonney/dev_src/ardupilot/build 
Autoconfiguration                        : enabled 
Setting board to                         : px4-v2 
Using toolchain                          : arm-none-eabi 
Checking for 'clang++' (C++ compiler)    : /usr/bin/clang++ 
Checking for 'clang' (C compiler)        : /usr/bin/clang 
Checking for HAVE_CMATH_ISFINITE         : no 
Checking for HAVE_CMATH_ISINF            : no 
Checking for HAVE_CMATH_ISNAN            : no 
Checking for header endian.h                   : not found 
Checking for header byteswap.h                 : not found 
Checking for program 'cmake'                   : /usr/local/bin/cmake 
Checking cmake version                         : 3.6.1 
Checking for program 'ninja, ninja-build'      : not found 
Checking for program 'cp'                      : /bin/cp 
Checking for program 'python'                  : /usr/bin/python 
Checking for python version >= 2.7.0           : 2.7.10 
Source is git repository                       : yes 
Update submodules                              : yes 
Checking for program 'git'                     : /usr/local/bin/git 
Gtest                                          : PX4 boards currently don't support compiling gtest 
Checking for program 'arm-none-eabi-size'      : /usr/local/bin/arm-none-eabi-size 
Benchmarks                                     : disabled 
Unit tests                                     : disabled 
'configure' finished successfully (0.830s)

Hi Bill. As discussed I did try to get waf building on my old OSX box but I get a different error to you - see below. I’ll log an issue for mine and see what the waf guru’s think.

In file included from usbdev/cdcacm.c:56:0:
/Users/grant/uav/ardupilot/build/px4-v2/modules/PX4Firmware/px4fmu-v2/NuttX/nuttx/include/nuttx/serial/serial.h:191:15: note: ‘onrxdeque’ declared here
CODE void (*onrxdeque)(FAR struct uart_dev_s *dev);

[ 15/353] Compiling libraries/AP_AccelCal/AP_AccelCal.cpp
clang: fatal error: optimization flag ‘-fno-strength-reduce’ is not supported

[ 16/353] Compiling libraries/AP_AccelCal/AccelCalibrator.cpp
Waf: Leaving directory `/Users/grant/uav/ardupilot/build/px4-v2’
Build failed
-> task in ‘ArduCopter_libs’ failed (exit status 1):
{task 30647840: cxx AP_AccelCal.cpp -> AP_AccelCal.cpp.4.o}
[’/usr/bin/clang++’, ‘-DCONFIG_ARCH_BOARD_PX4FMU_V2’, ‘-D__STDC_FORMAT_MACROS’, ‘-D__PX4_NUTTX’, ‘-D__DF_NUTTX’, ‘-g’, ‘-fno-exceptions’, ‘-fno-rtti’, ‘-std=gnu++0x’, ‘-fno-threadsafe-statics’, ‘-DCONFIG_WCHAR_BUILTIN’, ‘-D__CUSTOM_FILE_IO__’, ‘-Wall’, ‘-Werror’, ‘-Wextra’, ‘-Wno-sign-compare’, ‘-Wfloat-equal’, ‘-Wpointer-arith’, ‘-Wmissing-declarations’, ‘-Wno-unused-parameter’, ‘-Werror=format-security’, ‘-Werror=array-bounds’, ‘-Wfatal-errors’, ‘-Werror=unused-variable’, ‘-Werror=reorder’, ‘-Werror=uninitialized’, ‘-Werror=init-self’, ‘-Wframe-larger-than=1024’, ‘-Werror=unused-but-set-variable’, ‘-Wformat=1’, ‘-Wdouble-promotion’, ‘-Werror=double-promotion’, ‘-Wno-missing-field-initializers’, ‘-Os’, ‘-fno-strict-aliasing’, ‘-fomit-frame-pointer’, ‘-funsafe-math-optimizations’, ‘-ffunction-sections’, ‘-fdata-sections’, ‘-fno-strength-reduce’, ‘-fno-builtin-printf’, ‘-fvisibility=hidden’, ‘-include’, ‘visibility.h’, ‘-mcpu=cortex-m4’, ‘-mthumb’, ‘-march=armv7e-m’, ‘-mfpu=fpv4-sp-d16’, ‘-mfloat-abi=hard’, ‘-nodefaultlibs’, ‘-nostdlib’, ‘-std=gnu++11’, ‘-fdata-sections’, ‘-ffunction-sections’, ‘-fno-exceptions’, ‘-fsigned-char’, ‘-Wall’, ‘-Wextra’, ‘-Wformat’, ‘-Wshadow’, ‘-Wpointer-arith’, ‘-Wcast-align’, ‘-Wundef’, ‘-Wno-unused-parameter’, ‘-Wno-missing-field-initializers’, ‘-Wno-reorder’, ‘-Wno-redundant-decls’, ‘-Wno-unknown-pragmas’, ‘-Werror=format-security’, ‘-Werror=array-bounds’, ‘-Werror=uninitialized’, ‘-Werror=init-self’, ‘-Wfatal-errors’, ‘-fcolor-diagnostics’, ‘-Wno-gnu-designator’, ‘-Wno-inconsistent-missing-override’, ‘-Wno-mismatched-tags’, ‘-Wno-gnu-variable-sized-type-not-at-end’, ‘-Wno-c++11-narrowing’, ‘-Wlogical-op’, ‘-Wframe-larger-than=1300’, ‘-fsingle-precision-constant’, ‘-Wno-error=double-promotion’, ‘-Wno-error=missing-declarations’, ‘-Wno-error=float-equal’, ‘-Wno-error=undef’, ‘-Wno-error=cpp’, ‘–target=arm-none-eabi’, ‘–gcc-toolchain=/usr/local’, ‘–sysroot=/usr/local/Cellar/gcc-arm-none-eabi/20140805/bin/…/arm-none-eabi’, ‘-B/usr/local/bin’, ‘-include’, ‘ap_config.h’, ‘-Ilibraries’, ‘-Ilibraries/GCS_MAVLink’, ‘-I.’, ‘-I…/…/libraries’, ‘-I…/…/libraries/AP_Common/missing’, ‘-I…/…/modules/PX4Firmware/src’, ‘-Imodules/PX4Firmware’, ‘-Imodules/PX4Firmware/src’, ‘-I…/…/modules/PX4Firmware/src/modules’, ‘-I…/…/modules/PX4Firmware/src/include’, ‘-I…/…/modules/PX4Firmware/src/lib’, ‘-I…/…/modules/PX4Firmware/src/platforms’, ‘-I…/…/modules/PX4Firmware/src/drivers/boards/px4fmu-v2’, ‘-Imodules/PX4Firmware/src/modules/px4_messages’, ‘-Imodules/PX4Firmware/src/modules’, ‘-I…/…/modules/PX4Firmware/mavlink/include/mavlink’, ‘-I…/…/modules/PX4Firmware/src/lib/DriverFramework/framework/include’, ‘-IArduCopter/src/lib/matrix’, ‘-I…/…/ArduCopter/src/lib/matrix’, ‘-Imodules/PX4Firmware/px4fmu-v2/NuttX/nuttx-export/include’, ‘-Imodules/PX4Firmware/px4fmu-v2/NuttX/nuttx-export/include/cxx’, ‘-Imodules/PX4Firmware/px4fmu-v2/NuttX/nuttx-export/arch/chip’, ‘-Imodules/PX4Firmware/px4fmu-v2/NuttX/nuttx-export/arch/common’, ‘-DSKETCHBOOK="/Users/grant/uav/ardupilot"’, ‘-DCONFIG_HAL_BOARD=HAL_BOARD_PX4’, ‘-DHAVE_STD_NULLPTR_T=0’, ‘-DAPM_BUILD_DIRECTORY=APM_BUILD_ArduCopter’, ‘-DSKETCH=“ArduCopter”’, ‘-DSKETCHNAME=“ArduCopter”’, ‘…/…/libraries/AP_AccelCal/AP_AccelCal.cpp’, ‘-c’, ‘-o/Users/grant/uav/ardupilot/build/px4-v2/libraries/AP_AccelCal/AP_AccelCal.cpp.4.o’]
MBPro1:ardupilot grant$

@gmorph you are building for px4-v2 with clang? Is that intentional? I think this would happen in waf only if for some reason you have CXX env var set by mistake or you don’t have the toolchain in your path.

@guludo any idea?

@lucasdemarchi It seems @billb actually has the toolchain in his path:

Checking for program 'arm-none-eabi-size'      : /usr/local/bin/arm-none-eabi-size

Waf tries the clang compiler before gcc when checking for a compiler on OSX. @billb could you please share the output of the px4_msg_gen target? You’ve just posted the output of the configure step.

By what @gmorph’s posted, it seems that cross-compilation with clang is indeed broken.

A workaround is passing --check-gxx-compiler g++ to the configure command, so that it only finds the GNU compiler.

From my limited waf understanding on OSX it seems to look for clang first and if it finds it just uses that. I have gcc in my path :

MBPro1:~ grant$ which arm-none-eabi-size

As Gustavo suggested I ran with the flag (note its check-cxx - not check-gxx)

./modules/waf/waf-light configure --board px4-v2 --check-cxx-compiler g++
./modules/waf/waf-light build --target bin/arducopter-quad

and success it worked! Thanks!

@Bill is your waf working yet?

1 Like

Haven’t tried yet, been too busy… But I’ll try again soon

@guludo can we change the order so gcc is always the first one?

August 18

@guludo can we change the
order so gcc is always the first one?

Yep. That should be easy.

Yep, s,--check-gxx-compiler,--check-cxx-compiler, :slight_smile:

This works, thanks :slight_smile:

configure works, build fails

@billb could you please share the output of the px4_msg_gen target

I would if I knew what it was, I have no idea about waf or where it puts build files… it’s all new, so some hand holding helps, I learn fast :wink:

Works fine for me for both px4-v2 and px4-v4 targets. Maybe try a fresh clone of the source tree and submodules?

with a clean build it works, but with my current repo This is the error I’m getting. Maybe you can improve the script somehow. The other thing. What’s the bets docs to get a user guid to was builds so we can understand the build better? was is new to me, so I need a quick start guide so I can at least figure out how to diagnose some of the issues.

I really just don’t like blasting the repo as first course of action, since there always some wip in a branch happening. (or historical stuff i’ve fiddled with in the past and maybe useful stuff to me )

bonney@MacVan:ardupilot (master)$ waf build --target bin/arducopter-quad Waf: Entering directory/Users/bonney/dev_src/ardupilot/build/px4-v2’
[13/14] CMake Build px4 msg_gen
[ 0%] Built target git_gencpp
[ 0%] Built target git_genmsg
[100%] Built target msg_gen
[14/14] CMake Build px4 prebuild_targets
[ 0%] Built target __nuttx_patch_px4fmu-v2
[ 0%] Generating nuttx_copy_px4fmu-v2.stamp
cp: cannot overwrite directory /Users/bonney/dev_src/ardupilot/build/px4-v2/modules/PX4Firmware/px4fmu-v2/NuttX/./nuttx/arch/arm/include/board with non-directory /Users/bonney/dev_src/ardupilot/modules/PX4NuttX/./nuttx/arch/arm/include/board
cp: symlink: /Users/bonney/dev_src/ardupilot/modules/PX4NuttX/nuttx/configs/px4io-v2/src: File exists
cp: cannot overwrite directory /Users/bonney/dev_src/ardupilot/build/px4-v2/modules/PX4Firmware/px4fmu-v2/NuttX/./nuttx/arch/arm/src/chip with non-directory /Users/bonney/dev_src/ardupilot/modules/PX4NuttX/./nuttx/arch/arm/src/chip
cp: cannot overwrite directory /Users/bonney/dev_src/ardupilot/build/px4-v2/modules/PX4Firmware/px4fmu-v2/NuttX/./nuttx/include/apps with non-directory /Users/bonney/dev_src/ardupilot/modules/PX4NuttX/./nuttx/include/apps
cp: cannot overwrite directory /Users/bonney/dev_src/ardupilot/build/px4-v2/modules/PX4Firmware/px4fmu-v2/NuttX/./nuttx/include/arch with non-directory /Users/bonney/dev_src/ardupilot/modules/PX4NuttX/./nuttx/include/arch
make[3]: *** [nuttx_copy_px4fmu-v2.stamp] Error 1
make[2]: *** [CMakeFiles/__nuttx_copy_px4fmu-v2.dir/all] Error 2
make[1]: *** [CMakeFiles/prebuild_targets.dir/rule] Error 2
make: *** [prebuild_targets] Error 2

Waf: Leaving directory /Users/bonney/dev_src/ardupilot/build/px4-v2' Build failed -> task in 'px4_prebuild_targets' failed (exit status 2): {task 4581333264: cmake_build_task -> } ['/usr/local/bin/cmake', '--build', '/Users/bonney/dev_src/ardupilot/build/px4-v2/modules/PX4Firmware', '--target', 'prebuild_targets']

I would try:

waf distclean git submodule deinit -f .

Then try to build again.

Docs specific to ArduPilot are at: Like it says there, if you want to learn more about Waf you can read the book.

1 Like

you should add a link the the developer wiki

Thanks for info :slight_smile: i try it later

@OXINARF That worked thanks

The intention was to update the docs there. However we have too many scattered info about building in the site… We decided to go with a clean approach in the repo instead.

It’s ok being it github but a link from the wiki to the page would really help.

Can we put all of this into a script like we have for Ubuntu? That script works great!

In master branch you don’t need this option anymore. The following should just do the right thing:

./waf configure --board px4-v2
./waf --targets bin/arducopter-quad