Local compile error for STARTUP & SYSTEM_MODE

For future reference (so others can search for it):

Problem: when compiling locally, you’ll get errors for the macros STARTUP and SYSTEM_MODE as the ouput below.
Solution: #include “application.h” at the top of your main source file.

Building cpp file: …/…/…/myproject//src/myproject.cpp
Invoking: ARM GCC CPP Compiler
mkdir -p …/build/target/user/platform-8-m/myproject/src/
arm-none-eabi-gcc -DSTM32_DEVICE -DSTM32F2XX -DPLATFORM_THREADING=1 -DPLATFORM_ID=8 -DPLATFORM_NAME=photon -DUSBD_VID_SPARK=0x2B04 -DUSBD_PID_DFU=0xD008 -DUSBD_PID_CDC=0xC008 -DSPARK_PLATFORM -DFLASHEE_EEPROM -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb -DINCLUDE_PLATFORM=1 -DPRODUCT_ID=8 -DPRODUCT_FIRMWARE_VERSION=65535 -DUSE_STDPERIPH_DRIVER -DDFU_BUILD_ENABLE -DSYSTEM_VERSION_STRING=0.6.2 -DRELEASE_BUILD -I./inc -I…/wiring/inc -I…/system/inc -I…/services/inc -I…/communication/src -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/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…/dynalib/inc -I…/…/…/myproject//src -I./libraries -I…/…/…/myproject//src -I…/…/…/myproject//src -I…/…/…/myproject//src -I…/…/…/myproject//src -I…/…/…/myproject/lib/AccelStepperSpark/src -I…/…/…/myproject/lib/DACx311/src -I…/…/…/myproject/lib/GSL1680/src -I…/…/…/myproject/lib/MAX6639/src -I…/…/…/myproject/lib/MCP3424/src -I…/…/…/myproject/lib/MQTT/src -I…/…/…/myproject/lib/PID/src -I…/…/…/myproject/lib/RA8875/src -I…/…/…/myproject/lib/SparkIntervalTimer/src -I…/…/…/myproject/lib/TCA6408/src -I…/…/…/myproject/lib/spi_flash/src -I. -MD -MP -MF …/build/target/user/platform-8-m/myproject/src/myproject.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=BCM9WCDUSI14 -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc -DLOG_INCLUDE_SOURCE_INFO=1 -DPARTICLE_USER_MODULE -DUSE_THREADING=0 -DUSE_THREADING=0 -DUSE_SPI=SPI -DUSE_CS=A2 -DUSE_SPI=SPI -DUSE_CS=A2 -DUSER_FIRMWARE_IMAGE_SIZE=0x20000 -DUSER_FIRMWARE_IMAGE_LOCATION=0x80A0000 -DMODULAR_FIRMWARE=1 -DMODULE_VERSION=4 -DMODULE_FUNCTION=5 -DMODULE_INDEX=1 -DMODULE_DEPENDENCY=4,2,108 -D_WINSOCK_H -D_GNU_SOURCE -DLOG_MODULE_CATEGORY="“app”" -fno-exceptions -fno-rtti -fcheck-new -std=gnu++11 -c -o …/build/target/user/platform-8-m/myproject/src/myproject.o …/…/…/myproject//src/myproject.cpp
…/…/…/myproject//src/myproject.cpp:9:9: error: expected constructor, destructor, or type conversion before ‘(’ token
STARTUP(WiFi.selectAntenna(ANT_EXTERNAL));
^
…/…/…/myproject//src/myproject.cpp:14:13: error: expected constructor, destructor, or type conversion before ‘(’ token
SYSTEM_MODE(MANUAL);

@jenschr, the reason this is needed is that the Web IDE, much like Arduino, runs a pre-processor which, among other things, adds #include "Particle.h" to the code. You may also find that you need to rename your application .ino file to .cpp and that function declarations need to be added at the top of your application. Pre-processors can really spoil us:wink:

Yup. Some minutes ago I added a pull request to the docs for adding these two things :wink:
(I just added it here for reference)

1 Like