mcci-catena / arduino-lmic

LoraWAN-MAC-in-C library, adapted to run under the Arduino environment
https://forum.mcci.io/c/device-software/arduino-lmic/
MIT License
641 stars 208 forks source link

Examples fail to compile with platformio #183

Closed frazar closed 5 years ago

frazar commented 5 years ago

For some reason, when compiling with platformio, the compiler halts because the do_send() function is used a few lines before it is defined.

The error messages reported here was obtained with the ttn-abp.ino example, but this issue affects most of the examples.

Relevant error message

src/main.cpp: In function 'void onEvent(ev_t)':
src/main.cpp:138:82: error: 'do_send' was not declared in this scope
os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);
^
*** [.pioenvs/megaatmega2560/src/main.cpp.o] Error 1

Steps to reproduce

  1. Setup a new platformio project with

    platformio init --board megaatmega2560
  2. Edit the platformio.ini file so that it looks like this

    [env:megaatmega2560]
    platform = atmelavr
    board = megaatmega2560
    framework = arduino
    lib_deps =
        MCCI LoRaWAN LMIC library=https://github.com/mcci-catena/arduino-lmic/archive/master.zip
    build_flags =
        -DCOMPILE_REGRESSION_TEST
  3. Copy-paste the ttn-abp.ino example into the src/main.cpp file. Or if yor're lazy

    curl https://raw.githubusercontent.com/mcci-catena/arduino-lmic/master/examples/ttn-abp/ttn-abp.ino --output src/main.cpp
  4. Try to compile the project

    platformio run

Full error message

Processing megaatmega2560 (platform: atmelavr; board: megaatmega2560; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
PLATFORM: Atmel AVR > Arduino Mega or Mega 2560 ATmega2560 (Mega 2560)
SYSTEM: ATMEGA2560 16MHz 8KB RAM (248KB Flash)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 27 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <MCCI LoRaWAN LMIC library> 2.2.2
|   |-- <SPI> 1.0
|-- <SPI> 1.0
Compiling .pioenvs/megaatmega2560/src/main.cpp.o
Compiling .pioenvs/megaatmega2560/liba44/SPI/SPI.cpp.o
Compiling .pioenvs/megaatmega2560/libe6e/MCCI LoRaWAN LMIC library/aes/ideetron/AES-128_V10.cpp.o
Compiling .pioenvs/megaatmega2560/libe6e/MCCI LoRaWAN LMIC library/aes/lmic.c.o
src/main.cpp: In function 'void onEvent(ev_t)':
src/main.cpp:138:82: error: 'do_send' was not declared in this scope
os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);
^
*** [.pioenvs/megaatmega2560/src/main.cpp.o] Error 1
===================================================================================== [ERROR] Took 0.93 seconds =====================================================================================
frazar commented 5 years ago

I investigated more and it turned out that the examples compile just fine if I save them with the ".ino" extension rather than the ".cpp" extension!