Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extern millis declaration #84

Closed
BlackEdder opened this issue Jan 15, 2020 · 7 comments
Closed

extern millis declaration #84

BlackEdder opened this issue Jan 15, 2020 · 7 comments

Comments

@BlackEdder
Copy link
Contributor

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);
}
@arkhipenko
Copy link
Owner

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

@TD-er
Copy link

TD-er commented Jan 16, 2020

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.

@arkhipenko
Copy link
Owner

arkhipenko commented Jan 16, 2020

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

@arkhipenko
Copy link
Owner

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

@theOtterWizard
Copy link

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

@arkhipenko
Copy link
Owner

Pushed into master as 3.1.2

@BlackEdder
Copy link
Contributor Author

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants