PX4 / PX4-Autopilot

PX4 Autopilot Software
https://px4.io
BSD 3-Clause "New" or "Revised" License
8.48k stars 13.51k forks source link

Cannot compile px4fmu-v2_default #10876

Closed matteoscanavino closed 5 years ago

matteoscanavino commented 5 years ago

Hello, I'm in trouble whith gcc compiler while trying to build px4 code.

As reported in https://dev.px4.io/en/setup/building_px4.html, I must have a supported GCC version to build make px4fmu-v2_default. I've followed the instructions in https://dev.px4.io/en/setup/dev_env_linux_ubuntu.html#nuttx-based-hardware, I've executed the script GCC 7-2017-q4 and reboot my computer. However, I still have arm-none-eabi-gcc 4.9.3 when I check the version (instead of version 7.2.1 as reported in the docs).

I've noticed that when executing sudo apt-get remove gcc-arm-embedded I got the following:

Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package gcc-arm-embedded

I'm working with Ubuntu 16.04 LTS. If I try to compile px4fmu-v2_default with my GCC, the process fails and the following error is give:

[644/646] Linking CXX executable nuttx_px4fmu-v2_default.elf FAILED: : && /opt/gcc-arm-none-eabi-4_9-2015q3/bin/arm-none-eabi-g++ -fno-common -ffunction-sections -fdata-sections -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fno-common -ffunction-sections -fdata-sections -g -fno-exceptions -fno-rtti -std=gnu++11 -fno-threadsafe-statics -DCONFIG_WCHAR_BUILTIN -DCUSTOM_FILE_IO -fcheck-new -Wall -Wextra -Werror -Warray-bounds -Wdisabled-optimization -Wdouble-promotion -Wfatal-errors -Wfloat-equal -Wformat-security -Winit-self -Wlogical-op -Wmissing-declarations -Wpointer-arith -Wshadow -Wuninitialized -Wunknown-pragmas -Wunused-variable -Wno-implicit-fallthrough -Wno-missing-field-initializers -Wno-missing-include-dirs -Wno-unused-parameter -Wunused-but-set-variable -Wformat=1 -Wno-overloaded-virtual -Wreorder -Wno-format-truncation -fvisibility=hidden -include visibility.h -fno-strict-aliasing -fomit-frame-pointer -fno-math-errno -funsafe-math-optimizations -ffunction-sections -fdata-sections -fno-strength-reduce -fno-builtin-printf -Os -DNDEBUG -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -nodefaultlibs -nostdlib -Wl,--warn-common,--gc-sections platforms/nuttx/CMakeFiles/nuttx_px4fmu-v2_default.elf.dir///src/platforms/empty.c.obj -o nuttx_px4fmu-v2_default.elf -L/home/matteo/src/Firmware/build/nuttx_px4fmu-v2_default/external/Install/lib -nodefaultlibs -nostdlib -fno-exceptions -fno-rtti -Wl,--script=/home/matteo/src/Firmware/build/nuttx_px4fmu-v2_default/NuttX/nuttx/configs/px4fmu-v2/scripts/ld.script -Wl,-Map=nuttx_px4fmu-v2_default.map -Wl,--warn-common -Wl,--gc-sections -Wl,--start-group NuttX/apps/libapps.a NuttX/nuttx/arch/arm/src/libarch.a NuttX/nuttx/binfmt/libbinfmt.a NuttX/nuttx/libc/libc.a NuttX/nuttx/configs/libconfigs.a NuttX/nuttx/libxx/libcxx.a NuttX/nuttx/drivers/libdrivers.a NuttX/nuttx/fs/libfs.a NuttX/nuttx/mm/libmm.a NuttX/nuttx/sched/libsched.a -Wl,--end-group -lm src/modules/uORB/libmodulesuORB.a src/drivers/barometer/ms5611/libdriversms5611.a src/drivers/differential_pressure/ms4525/libdriversms4525_airspeed.a src/drivers/distance_sensor/ll40ls/libdriversll40ls.a src/drivers/distance_sensor/sf0x/libdriverssf0x.a src/drivers/gps/libdriversgps.a src/drivers/imu/l3gd20/libdriversl3gd20.a src/drivers/imu/lsm303d/libdriverslsm303d.a src/drivers/imu/mpu6000/libdriversmpu6000.a src/drivers/imu/mpu9250/libdriversmpu9250.a src/drivers/magnetometer/hmc5883/libdrivershmc5883.a src/drivers/px4flow/libdriverspx4flow.a src/drivers/px4fmu/libdriverspx4fmu.a src/drivers/px4io/libdriverspx4io.a src/drivers/rgbled/libdriversrgbled.a src/drivers/stm32/adc/libdriversadc.a src/drivers/stm32/tone_alarm/libdriverstone_alarm.a src/drivers/vmount/libdriversvmount.a src/modules/sensors/libmodulessensors.a src/systemcmds/bl_update/libsystemcmdsbl_update.a src/systemcmds/hardfault_log/libsystemcmdshardfault_log.a src/systemcmds/mixer/libsystemcmdsmixer.a src/systemcmds/mtd/libsystemcmdsmtd.a src/systemcmds/param/libsystemcmdsparam.a src/systemcmds/perf/libsystemcmdsperf.a src/systemcmds/pwm/libsystemcmdspwm.a src/systemcmds/reboot/libsystemcmdsreboot.a src/systemcmds/top/libsystemcmds__top.a src/systemcmds/tune_control/libsystemcmdstune_control.a src/systemcmds/ver/libsystemcmdsver.a src/modules/camera_feedback/libmodules__camera_feedback.a src/modules/commander/libmodulescommander.a src/modules/events/libmodulesevents.a src/modules/land_detector/libmodulesland_detector.a src/modules/load_mon/libmodulesload_mon.a src/modules/mavlink/libmodulesmavlink.a src/modules/navigator/libmodulesnavigator.a src/modules/ekf2/libmodulesekf2.a src/modules/fw_att_control/libmodulesfw_att_control.a src/modules/fw_pos_control_l1/libmodules__fw_pos_control_l1.a src/modules/mc_att_control/libmodulesmc_att_control.a src/modules/mc_pos_control/libmodulesmc_pos_control.a src/modules/vtol_att_control/libmodulesvtol_att_control.a src/modules/logger/libmoduleslogger.a src/modules/dataman/libmodulesdataman.a src/modules/uORB/libmodulesuORB.a ROMFS/libromfs.a src/lib/drivers/airspeed/libdriversairspeed.a src/lib/led/libled.a src/lib/battery/libbattery.a src/lib/ecl/validation/libecl_validation.a src/lib/mixer/libmixer.a src/lib/tunes/libtunes.a src/lib/DriverFramework/framework/src/libdf_driver_framework.a src/lib/airspeed/libairspeed.a src/lib/ecl/EKF/libecl_EKF.a src/lib/ecl/geo_lookup/libecl_geo_lookup.a src/lib/ecl/attitude_fw/libecl_attitude_fw.a src/lib/landing_slope/liblanding_slope.a src/lib/ecl/l1/libecl_l1.a src/lib/ecl/tecs/libecl_tecs.a src/modules/fw_pos_control_l1/launchdetection/liblaunchdetection.a src/modules/fw_pos_control_l1/runway_takeoff/librunway_takeoff.a src/lib/circuit_breaker/libcircuit_breaker.a src/lib/conversion/libconversion.a src/lib/mathlib/libmathlib.a src/lib/ecl/geo/libecl_geo.a src/lib/controllib/libcontrollib.a src/lib/FlightTasks/libFlightTasks.a src/lib/FlightTasks/tasks/ManualAltitudeSmooth/libFlightTaskManualAltitudeSmooth.a src/lib/FlightTasks/tasks/ManualPositionSmooth/libFlightTaskManualPositionSmooth.a src/lib/FlightTasks/tasks/ManualPositionSmoothVel/libFlightTaskManualPositionSmoothVel.a src/lib/FlightTasks/tasks/ManualPosition/libFlightTaskManualPosition.a src/lib/FlightTasks/tasks/ManualAltitude/libFlightTaskManualAltitude.a src/lib/FlightTasks/tasks/ManualStabilized/libFlightTaskManualStabilized.a src/lib/FlightTasks/tasks/Manual/libFlightTaskManual.a src/lib/FlightTasks/tasks/AutoLine/libFlightTaskAutoLine.a src/lib/FlightTasks/tasks/AutoMapper/libFlightTaskAutoMapper.a src/lib/FlightTasks/tasks/AutoLineSmoothVel/libFlightTaskAutoLineSmoothVel.a src/lib/FlightTasks/tasks/Utility/libFlightTaskUtility.a src/lib/FlightTasks/tasks/AutoMapper2/libFlightTaskAutoMapper2.a src/lib/FlightTasks/tasks/AutoFollowMe/libFlightTaskAutoFollowMe.a src/lib/FlightTasks/tasks/Auto/libFlightTaskAuto.a src/lib/FlightTasks/tasks/Offboard/libFlightTaskOffboard.a src/lib/FlightTasks/tasks/Failsafe/libFlightTaskFailsafe.a src/lib/FlightTasks/tasks/Transition/libFlightTaskTransition.a src/lib/FlightTasks/tasks/FlightTask/libFlightTask.a src/lib/WeatherVane/libWeatherVane.a src/lib/pwm_limit/libpwm_limit.a src/lib/version/libversion.a src/platforms/common/libplatformscommon.a platforms/nuttx/src/px4_layer/libpx4_layer.a NuttX/nuttx/arch/arm/src/libarch.a src/drivers/boards/px4fmu-v2/libdrivers_board.a src/drivers/stm32/libdrivers_arch.a src/drivers/boards/common/libdrivers_boards_common.a src/drivers/boards/common/stm32/libdrivers_boards_common_arch.a src/modules/systemlib/libsystemlib.a src/lib/drivers/device/libdriversdevice.a src/lib/drivers/led/libdriversled.a src/lib/parameters/libparameters.a src/lib/cdev/libcdev.a src/lib/parameters/flashparams/libflashparams.a NuttX/nuttx/arch/arm/src/libarch.a src/drivers/boards/px4fmu-v2/libdrivers_board.a src/drivers/stm32/libdrivers_arch.a src/drivers/boards/common/libdrivers_boards_common.a src/drivers/boards/common/stm32/libdrivers_boards_common_arch.a src/modules/systemlib/libsystemlib.a src/lib/drivers/device/libdriversdevice.a src/lib/drivers/led/libdriversled.a src/lib/parameters/libparameters.a src/lib/cdev/libcdev.a src/lib/parameters/flashparams/libflashparams.a NuttX/apps/libapps.a src/lib/perf/libperf.a src/lib/parameters/tinybson/libtinybson.a NuttX/nuttx/libxx/libcxx.a NuttX/nuttx/libc/libc.a NuttX/nuttx/drivers/libdrivers.a NuttX/nuttx/fs/libfs.a NuttX/nuttx/mm/libmm.a NuttX/nuttx/sched/libsched.a -lm -lgcc msg/libuorb_msgs.a && : /opt/gcc-arm-none-eabi-4_9-2015q3/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: nuttx_px4fmu-v2_default.elf section .text' will not fit in regionflash' /opt/gcc-arm-none-eabi-4_9-2015q3/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: address 0x8105fa4 of nuttx_px4fmu-v2_default.elf section __param' is not within regionflash' /opt/gcc-arm-none-eabi-4_9-2015q3/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: address 0x8105fa4 of nuttx_px4fmu-v2_default.elf section `param' is not within region flash' /opt/gcc-arm-none-eabi-4_9-2015q3/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: address 0x8105fa4 of nuttx_px4fmu-v2_default.elf section__param' is not within region flash' /opt/gcc-arm-none-eabi-4_9-2015q3/bin/../lib/gcc/arm-none-eabi/4.9.3/../../../../arm-none-eabi/bin/ld: regionflash' overflowed by 27989 bytes collect2: error: ld returned 1 exit status ninja: build stopped: subcommand failed. Makefile:176: recipe for target 'px4fmu-v2_default' failed make: *** [px4fmu-v2_default] Error 1

Any suggestions on how to fix it? Thank-you in advance

hamishwillee commented 5 years ago

The build error is definitely because you're not using the right GCC compiler - as you said. YOu'll need to uninstall arm-none-eabi-gcc 4.9.3 or do whatever it takes to point to GCC 7-2017-q4 -

If you followed this fully you will have done this before installing the new toolchain:

If you were installing on a clean system I would suggest just running the standard build script - it does the same things as the instructions but you don't have to think about it.

matteoscanavino commented 5 years ago

@hamishwillee Thankyou. When I run sudo apt-get remove gcc-arm-none-eabi gdb-arm-none-eabi binutils-arm-none-eabi gcc-arm-embedded I get this message:

Reading package lists... Done Building dependency tree
Reading state information... Done E: Unable to locate package gcc-arm-embedded

Furthermore arm-none-eabi-gcc --version gives: arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 4.9.3 20150529 (release) [ARM/embedded-4_9-branch revision 227977]

It seems I cannot completely uninstall GCC 4.9.3: I don't know how to install GCC 7 or to point to it...

If I run the standard build script you linked, even if at the end I reboot my computer, I still have GCC 4.9.3 and I'm not able to build the firmware as I got the error:

Makefile:176: recipe for target 'px4fmu-v2_default' failed make: *** [px4fmu-v2_default] Error 1

matteoscanavino commented 5 years ago

I solved the problem removing manually the folder gcc-arm-none-eabi-4_9-2015q3: for some strange reason, when I tried to compile GCC4.9.3 was used by default. By removing the folder, GCC7-2017-q4 was used and I was able to build the code.