Skip to content

extern millis declaration #84

Closed
Closed

Description

@BlackEdder

I get the follow error with later versions of TaskScheduler/esp:

 In file included from lib/painlessMesh/src/painlessMeshConnection.h:6:0,
                 from lib/painlessMesh/src/painlessMeshConnection.cpp:9:
/root/.platformio/lib/TaskScheduler_ID721/src/TaskSchedulerDeclarations.h:48:22: error: previous declaration of 'long unsigned int millis()' with 'C++' linkage
 extern unsigned long millis(void);
                      ^
In file included from /root/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266WiFi/src/WiFiClient.h:25:0,
                 from /root/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266WiFi/src/ESP8266WiFi.h:39,
                 from lib/painlessMesh/src/painlessMeshConnection.h:11,
                 from lib/painlessMesh/src/painlessMeshConnection.cpp:9:
/root/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/Arduino.h:187:26: error: conflicts with new declaration with 'C' linkage
 unsigned long millis(void);
                          ^
In file included from lib/painlessMesh/src/painlessMeshConnection.h:6:0,
                 from lib/painlessMesh/src/painlessMeshConnection.cpp:9:
/root/.platformio/lib/TaskScheduler_ID721/src/TaskSchedulerDeclarations.h:47:22: error: previous declaration of 'long unsigned int micros()' with 'C++' linkage
 extern unsigned long micros(void);
                      ^
In file included from /root/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266WiFi/src/WiFiClient.h:25:0,
                 from /root/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266WiFi/src/ESP8266WiFi.h:39,
                 from lib/painlessMesh/src/painlessMeshConnection.h:11,
                 from lib/painlessMesh/src/painlessMeshConnection.cpp:9:
/root/.platformio/packages/framework-arduinoespressif8266/cores/esp8266/Arduino.h:188:26: error: conflicts with new declaration with 'C' linkage
 unsigned long micros(void);
                          ^
*** [.pio/build/nodemcuv2/lib771/painlessMesh/painlessMeshConnection.cpp.o] Error 1

I assume this would be solved by wrapping them as follows in the TaskSchedulerDeclarations file (but have not tested this).

extern "C"
{
   unsigned long micros(void);
   unsigned long millis(void);
}

Activity

  1. arkhipenko commented on Jan 16, 2020

    @arkhipenko
    Owner

    Would it also help if I moved this declaration into TaskScheduler.h file, which must only be included once?

  2. TD-er commented on Jan 16, 2020

    @TD-er

    declare it using extern in a .h file and implement it in only a single .cpp file.

    Something like this...

    some.h file:

    extern unsigned long micros(void);
    extern unsigned long millis(void);

    some.cpp file:

    #include "some.h"
    
    unsigned long micros(void) { .... }
    unsigned long millis(void) { .... }

    This allows the .h file to be included as much as you like.
    The same for (global) variables.
    Declare as extern and construct in only a single .cpp file.

  3. arkhipenko commented on Jan 16, 2020

    @arkhipenko
    Owner

    I can't have any .cpp files in the library due to the way Arduino IDE handles external #define statements...

  4. arkhipenko commented on Jan 17, 2020

    @arkhipenko
    Owner

    Could you please check if the version I just pushed into "testing" branch solves the issue?
    Thx

  5. theOtterWizard commented on Jan 17, 2020

    @theOtterWizard

    I had the same issue but the testing branch version solved the compilation errors for me.

  6. arkhipenko commented on Jan 17, 2020

    @arkhipenko
    Owner

    Pushed into master as 3.1.2

  7. BlackEdder commented on Jan 20, 2020

    @BlackEdder
    ContributorAuthor

    Thank you this has now been solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions