[ISSUE] "Compile application (local)" fails after renaming a source file

Supporting information

  • VSCode Version: 1.27.2 (1.27.2)
  • OS Version: macOS Sierra 10.12.6 (16G1510)
  • Other extensions installed: many (39)

Steps to Reproduce:

  1. ⇧⌘P => Particle: Create New Project => PlaygroundOne
  2. Add a file PlayOne.cpp (content see bottom) to the src folder
  3. ⇧⌘B => Particle: Compile application (local)
  4. Rename the file PlayOne.cpp to PlayTwo.cpp
  5. ⇧⌘B => Particle: Compile application (local)
    ==> FAILS withs "multiple definition of …
Invoking: ARM GCC C++ Linker
mkdir -p /Users/bittailor/Documents/Code/particle.io/bt-current-monitor/firmware/PlaygroundOne/target/
arm-none-eabi-g++ -DSTM32_DEVICE -DSTM32F2XX -DPLATFORM_THREADING=1 -DPLATFORM_ID=6 -DPLATFORM_NAME=photon -DUSBD_VID_SPARK=0x2B04 -DUSBD_PID_DFU=0xD006 -DUSBD_PID_CDC=0xC006 -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb -DINCLUDE_PLATFORM=1 -fno-builtin -DUSE_STDPERIPH_DRIVER -DDFU_BUILD_ENABLE -DSYSTEM_VERSION_STRING=0.7.0 -DRELEASE_BUILD -Werror -I./inc -I../../../user/inc -I../../../dynalib/inc -I../../../services/inc -I../../../hal/inc -I../../../hal/shared -I../../../hal/src/photon -I../../../hal/src/stm32f2xx -I../../../hal/src/stm32 -I../../../hal/src/photon/api -I../../../hal/src/photon/include -I../../../hal/src/photon/wiced/security/BESL/host/WICED/ -I../../../hal/src/photon/wiced/security/BESL/include -I../../../hal/src/photon/wiced/security/BESL -I../../../hal/src/photon/wiced/security/BESL/crypto -I../../../hal/src/photon/wiced/WWD/include/ -I../../../hal/src/photon/wiced/platform/include/ -I../../../hal/src/photon/wiced/platform/GCC/ -I../../../hal/src/photon/wiced/security/BESL/supplicant/ -I../../../hal/src/photon/libraries/crypto -I../../../system/inc -I../../../rt-dynalib/inc -I../../../wiring/inc -I../../../modules/photon/system-part1/inc -I../../../modules/shared/stm32f2xx/inc -I../../../platform/shared/inc -I../../../platform/MCU/STM32F2xx/CMSIS/Include -I../../../platform/MCU/STM32F2xx/CMSIS/Device/ST/Include -I../../../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc -I../../../platform/MCU/shared/STM32/inc -I../../../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc -I../../../platform/MCU/STM32F2xx/STM32_USB_Device_Driver/inc -I../../../platform/MCU/STM32F2xx/STM32_USB_Host_Driver/inc -I../../../platform/MCU/STM32F2xx/STM32_USB_OTG_Driver/inc -I. -MD -MP -MF /Users/bittailor/Documents/Code/particle.io/bt-current-monitor/firmware/PlaygroundOne/target/PlaygroundOne.elf.d -ffunction-sections -fdata-sections -Wall -Wno-switch -Wno-error=deprecated-declarations -fmessage-length=0 -fno-strict-aliasing -DSPARK=1 -DPARTICLE=1 -Wundef -DSTART_DFU_FLASHER_SERIAL_SPEED=14400 -DSTART_YMODEM_FLASHER_SERIAL_SPEED=28800 -DBOOTLOADER_SDK_3_3_0_PARTICLE -DPARTICLE_DCT_COMPATIBILITY -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc -DUSER_FIRMWARE_IMAGE_SIZE=0x20000 -DUSER_FIRMWARE_IMAGE_LOCATION=0x80A0000 -DMODULAR_FIRMWARE=1 -DMODULE_VERSION=5 -DMODULE_FUNCTION=5 -DMODULE_INDEX=1 -DMODULE_DEPENDENCY=4,2,207 -DMODULE_DEPENDENCY2=0,0,0 -D_WINSOCK_H -D_GNU_SOURCE /Users/bittailor/Documents/Code/particle.io/bt-current-monitor/firmware/PlaygroundOne/target//obj/src/module_info.o /Users/bittailor/Documents/Code/particle.io/bt-current-monitor/firmware/PlaygroundOne/target//obj/src/user_export.o /Users/bittailor/Documents/Code/particle.io/bt-current-monitor/firmware/PlaygroundOne/target//obj/src/user_module.o /Users/bittailor/Documents/Code/particle.io/bt-current-monitor/firmware/PlaygroundOne/target//obj/src/newlib_stubs.o  --output /Users/bittailor/Documents/Code/particle.io/bt-current-monitor/firmware/PlaygroundOne/target/PlaygroundOne.elf -Wl,--whole-archive../../../hal/src/photon/lib/STM32F2xx_Peripheral_Libraries.a -Wl,--no-whole-archive -nostartfiles -Xlinker --gc-sections -L../../../build/arm/linker/stm32f2xx  -L../../../build/target/user/platform-6-m/PlaygroundOne/ -L../../../build/target/services-dynalib/arm/ -L../../../build/target/hal-dynalib/platform-6-m/ -L../../../build/target/system-dynalib/platform-6-m/ -L../../../build/target/rt-dynalib/platform-6-m/ -L../../../build/target/wiring/platform-6-m/ -L../../../build/target/communication-dynalib/platform-6-m/ -L../../../build/target/platform/platform-6-m/ -L../../../build/target/wiring_globals/platform-6-m/ -L../../../hal/src/photon/lib/ -L../../../build/arm/linker -Wl,--whole-archive -luser -lhal-dynalib-lservices-dynalib -lsystem-dynalib -lrt-dynalib -lwiring -lcommunication-dynalib -lplatform -lwiring_globals -Wl,--no-whole-archive -lnosys --specs=nano.specs -L../../../modules/photon/system-part2 -L../../../modules/photon/system-part1 -L. -T./linker.ld -Wl,--defsym,USER_FIRMWARE_IMAGE_SIZE=0x20000 -Wl,--defsym,USER_FIRMWARE_IMAGE_LOCATION=0x80A0000 -Wl,-Map,/Users/bittailor/Documents/Code/particle.io/bt-current-monitor/firmware/PlaygroundOne/target/PlaygroundOne.map
../../../build/target/user/platform-6-m/PlaygroundOne//libuser.a(PlayTwo.o): In function `playIt()':
/Users/bittailor/Documents/Code/particle.io/bt-current-monitor/firmware/PlaygroundOne//src/PlayTwo.cpp:1: multiple definition of `playIt()'
../../../build/target/user/platform-6-m/PlaygroundOne//libuser.a(PlayOne.o):/Users/bittailor/Documents/Code/particle.io/bt-current-monitor/firmware/PlaygroundOne//src/PlayOne.cpp:1: first defined here
collect2: error: ld returned 1 exit status
make[2]: *** [/Users/bittailor/Documents/Code/particle.io/bt-current-monitor/firmware/PlaygroundOne/target/PlaygroundOne.elf] Error 1
make[2]: Leaving directory `/Users/bittailor/.particle/toolchains/deviceOS/0.7.0/firmware-0.7.0/modules/photon/user-part'
make[1]: *** [modules/photon/user-part] Error 2
make[1]: Leaving directory `/Users/bittailor/.particle/toolchains/deviceOS/0.7.0/firmware-0.7.0/main'
make: *** [compile-user] Error 2
The terminal process terminated with exit code: 2

So it looks the linker step includes both object files the old one PlayOne.o and the new one PlayTwo.o and not just the ones that still corresponds to a cpp source file. There is no clean task in the Build Tasks (⇧⌘B) to get rid of the stale object files.

The only workaround I found was to locate the object files in the ~/.particle folder:

/Users/<user>/.particle/toolchains/deviceOS/0.7.0/firmware-0.7.0/build/target/user/platform-6-m/PlaygroundOne/src

and delete them manually. Then compile and link works fine again.


Content of the PlayOne.cpp that is renamed to PlayTwo.cpp

void playIt() {
    
}

thanks for the report.

There is no clean task in the Build Tasks (⇧⌘B) to get rid of the stale object files.

that's the keyboard shortcut to view Build tasks. We have a number of Clean tasks available - to view, select "Terminal > Run Tasks..." from the main menu.

hope that helps!

Ok thanks, I found the ‘Particle: Clean application (local)’ by

⇧⌘P => Tasks: Run Task => Particle: Clean application (local)

This removes all object files and with this also the stale object files, so there is no need to locate them in the ~/.particle folder.

Is it expected that I need to run a clean after renaming or deleting a cpp source file or is this considered an issue of the build system?