I’m trying to use a local makefile in my APP directory to include a library located in a central location.
The following make command using the “latest” branch of firmware completes without problem:
sudo make clean all program-dfu APP=accel PLATFORM=photon
However, when I add a local makefile (called accel.mk) into the user/applications directory:
INCLUDE_DIRS += ./libraries/eMPL
INCLUDE_DIRS += ./libraries/eMPL/include
SRC += $(call target_files,,*.c)
CPPSRC += $(call target_files,,*.cpp)
I get the following error:
...
Building file: tests/bootloader/flashupdate.cpp
Invoking: ARM GCC CPP Compiler
mkdir -p ../build/target/user/platform-6-m/applications/accel4/tests/bootloader/
arm-none-eabi-gcc -DSTM32_DEVICE -DSTM32F2XX -DPLATFORM_THREADING=1 -DPLATFORM_ID=6 -DPLATFORM_NAME=photon -DUSBD_VID_SPARK=0x2B04 -DUSBD_PID_DFU=0xD006 -DUSBD_PID_CDC=0xC006 -DSPARK_PLATFORM -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb -DINCLUDE_PLATFORM=1 -DPRODUCT_ID=6 -DPRODUCT_FIRMWARE_VERSION=65535 -DMBEDTLS_CONFIG_FILE="<mbedtls_config.h>" -DUSE_STDPERIPH_DRIVER -DDFU_BUILD_ENABLE -DSYSTEM_VERSION_STRING=0.4.9 -DRELEASE_BUILD -I./inc -I../wiring/inc -I../system/inc -I../services/inc -I../communication/src -I../communication/lib/mbedtls/include -I../communication/lib/tropicssl/include -I../hal/inc -I../hal/shared -I../hal/src/photon -I../hal/src/stm32f2xx -I../hal/src/stm32 -I../hal/src/photon/api -I../platform/shared/inc -I../platform/MCU/STM32F2xx/STM32_USB_Host_Driver/inc -I../platform/MCU/STM32F2xx/STM32_USB_OTG_Driver/inc -I../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc -I../platform/MCU/STM32F2xx/STM32_USB_Device_Driver/inc -I../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc -I../platform/MCU/shared/STM32/inc -I../platform/MCU/STM32F2xx/CMSIS/Include -I../platform/MCU/STM32F2xx/CMSIS/Device/ST/Include -I../dynalib/inc -I./libraries/eMPL -I./libraries/eMPL/include -I./libraries -I. -MD -MP -MF ../build/target/user/platform-6-m/applications/accel4/tests/bootloader/flashupdate.o.d -ffunction-sections -fdata-sections -Wall -Wno-switch -Wno-error=deprecated-declarations -fmessage-length=0 -fno-strict-aliasing -DSPARK=1 -DPARTICLE=1 -DSTART_DFU_FLASHER_SERIAL_SPEED=14400 -DSTART_YMODEM_FLASHER_SERIAL_SPEED=28800 -DSPARK_PLATFORM_NET=BCM9WCDUSI09 -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc -DUSER_FIRMWARE_IMAGE_SIZE=0x20000 -DUSER_FIRMWARE_IMAGE_LOCATION=0x80A0000 -DMODULAR_FIRMWARE=1 -DMODULE_VERSION=3 -DMODULE_FUNCTION=5 -DMODULE_INDEX=1 -DMODULE_DEPENDENCY=4,2,11 -fno-exceptions -fno-rtti -fcheck-new -std=gnu++11 -c -o ../build/target/user/platform-6-m/applications/accel4/tests/bootloader/flashupdate.o tests/bootloader/flashupdate.cpp
tests/bootloader/flashupdate.cpp:27:33: fatal error: unit-test/unit-test.h: No such file or directory
#include "unit-test/unit-test.h"
^
compilation terminated.
../build/module.mk:227: recipe for target '../build/target/user/platform-6-m/applications/accel4/tests/bootloader/flashupdate.o' failed
make[2]: *** [../build/target/user/platform-6-m/applications/accel4/tests/bootloader/flashupdate.o] Error 1
make[2]: Leaving directory '/home/marc/projects/particle-firmware/user'
../../../build/recurse.mk:11: recipe for target 'user' failed
In my first run flashupdate.o is not a target. When I place the accel.mk in the applications/accel directory it is a target which then causes the compilation to fail.
What about my makefile is causing flashupdate to be a target?
I think I must be missing something from my local makefile.
I’ve scratched my head long and hard trying to figure this one out. I know I can add libraries within my app directory, but I’d like to share libraries among different APPs. I saw other forum posts which add libraries by editing the main makefile, but I think having a local makefile would be so much cleaner
Any ideas what I’m doing wrong?
Thanks
1 Like
Ok, I can get by this problem by adding the following in my accel.mk:
SRC += $(shell find applications/$(APP) -name "*.c")
CPPSRC += $(shell find applications/$(APP) -name "*.cpp")
Instead of:
SRC += $(call target_files,,*.c)
CPPSRC += $(call target_files,,*.cpp)
The target_files list is populated with all the files in the directory when using APPDIR, but not APP. For APP you need to specify the files more completely since target_files isn’t populated.
Would be nice if the makefile did some error checking to see if any application sources were added.
Even with the above changes I’m finding that the library isn’t getting included in the final application .elf target:
Invoking recipe from ../build/module.mk:183 to update target `../build/target/main/platform-0-lto/accel.elf'.
arm-none-eabi-g++ -DSTM32_DEVICE -DSTM32F10X_MD -DPLATFORM_THREADING=0 -DPLATFORM_ID=0 -DPLATFORM_NAME=core -DUSBD_VID_SPARK=0x1D50 -DUSBD_PID_DFU=0x607F -DUSBD_PID_CDC=0x607D -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb -flto -DINCLUDE_PLATFORM=1 -DPRODUCT_ID=0 -DPRODUCT_FIRMWARE_VERSION=65535 -DMBEDTLS_CONFIG_FILE="<mbedtls_config.h>" -DUSE_STDPERIPH_DRIVER -DDFU_BUILD_ENABLE -DSYSTEM_VERSION_STRING=0.4.9 -DRELEASE_BUILD -Werror -I../user/inc -I../wiring/inc -I../hal/inc -I../hal/shared -I../hal/src/core -I../hal/src/stm32 -I../system/inc -I../services/inc -I../communication/src -I../communication/lib/mbedtls/include -I../communication/lib/tropicssl/include -I../platform/shared/inc -I../platform/MCU/STM32F1xx/STM32_StdPeriph_Driver/inc -I../platform/MCU/STM32F1xx/STM32_USB_Device_Driver/inc -I../platform/MCU/STM32F1xx/SPARK_Firmware_Driver/inc -I../platform/MCU/shared/STM32/inc -I../platform/MCU/STM32F1xx/CMSIS/Include -I../platform/MCU/STM32F1xx/CMSIS/Device/ST/Include -I../platform/NET/CC3000/CC3000_Host_Driver -I../dynalib/inc -I. -MD -MP -MF ../build/target/main/platform-0-lto/accel.elf.d -ffunction-sections -fdata-sections -Wall -Wno-switch -Wno-error=deprecated-declarations -fmessage-length=0 -fno-strict-aliasing -DSPARK=1 -DPARTICLE=1 -DSTART_DFU_FLASHER_SERIAL_SPEED=14400 -DSTART_YMODEM_FLASHER_SERIAL_SPEED=28800 -DMODULE_VERSION=0 -DMODULE_FUNCTION=3 -DMODULE_DEPENDENCY=0,0,0 ../build/target/main/platform-0-lto/./src/module_info.o ../build/target/main/platform-0-lto/startup/startup_stm32f10x_md.o --output ../build/target/main/platform-0-lto/accel.elf -nostartfiles -Xlinker --gc-sections -flto -Os -fuse-linker-plugin -Tlinker_stm32f10x_md_dfu.ld -L../build/arm/linker --specs=nano.specs -lc -lnosys -u _printf_float -Wl,-Map,../build/target/main/platform-0-lto/accel.map -L../build/target/user/platform-0-lto/applications/accel/ -L../build/target/wiring/platform-0-lto/ -L../build/target/system/platform-0-lto/ -L../build/target/services/platform-0-lto/ -L../build/target/communication/platform-0-lto-prod-0/ -L../build/target/hal/platform-0-lto/ -L../build/target/platform/platform-0-lto/ -L../build/target/wiring_globals/platform-0-lto/ -L../build/target/newlib_nano/platform-0-lto -L../build/arm/linker -Wl,--whole-archive -lnewlib_nano -luser -lwiring -lhal -lsystem -lservices -lcommunication -lplatform -lwiring_globals -Wl,--no-whole-archive
##<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
/tmp/ccWFLYq6.ltrans12.ltrans.o: In function `setup':
/home/marc/projects/particle-firmware/main/applications/accel/application.cpp:107: undefined reference to `mpu_init(int_param_s*)'
collect2: error: ld returned 1 exit status
../build/module.mk:182: *** [../build/target/main/platform-0-lto/accel.elf] Error 1
#0 ../build/target/main/platform-0-lto/accel.elf at /home/marc/projects/particle-firmware/main/../build/module.mk:182
#1 elf at /home/marc/projects/particle-firmware/main/../build/module.mk:50
#2 all at /home/marc/projects/particle-firmware/main/../build/module.mk:48
It errors out because it can’t find the mpu_init function. This function is defined in the .h & .cpp file of the library that I included in my application.cpp:
#include "inv_mpu.h"
And this header is located in my INCLUDE_DIRS in the accel.mk file with:
INCLUDE_DIRS += ./libraries/eMPL
Not sure why this isn’t getting pulled in for the linking of the accel.elf.
Any ideas?
andrey
August 23, 2016, 7:46pm
4
I’ve had a similar problem. Apparently it’s not necessary to add custom INCLUDE_DIRS
and SRC
variables as the default makefile already searches recursively inside the app’s directory. The actual issue was that I was trying to compile .c
files – when I changed them to .cpp
, it worked.