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

Compilation Link error with multiple includes #142

Closed
PPCM opened this issue Mar 26, 2022 · 1 comment
Closed

Compilation Link error with multiple includes #142

PPCM opened this issue Mar 26, 2022 · 1 comment

Comments

@PPCM
Copy link

PPCM commented Mar 26, 2022

Hello,

I would to make my dev OOP, so each object need to include <TaskScheduler.h>
But it fails during the link process.
The platform used is a WEMOS D1 MINI ESP32

Here is a working example

config.h

#ifndef __CONFIG_H__
#define __CONFIG_H__

#define Test 123

#endif

main.h

#ifndef __MAIN_H__
#define __MAIN_H__

#include <TaskScheduler.h>

#include "config.h"

#endif

main.c

#include <Arduino.h>

#include "main.h"

void setup() {
  // put your setup code here, to run once:
}

void loop() {
  // put your main code here, to run repeatedly:
}

The compile complete correctly, it produce only one warning (already an issue)

Now if I include <TaskScheduler.h> in an other file, the linking process fails for multiple definition of elements
In the previous example modify following files
main.h

#ifndef __MAIN_H__
#define __MAIN_H__

#include <TaskScheduler.h>

#include "config.h"

#include "A.h"

#endif

A.h

#ifndef __A_H__
#define __A_H__

#include <TaskScheduler.h>

#include "config.h"

#endif

A.cpp

#include "A.h"

It produces the following error:

.pio\build\wemos_d1_mini32\src\main.cpp.o: In function `Task::isEnabled()':
C:\Users\ppcm\Documents\PlatformIO\Projects\Test/.pio\libdeps\wemos_d1_mini32\TaskScheduler\src/TaskScheduler.h:458: multiple definition of `Task::isEnabled()'
.pio\build\wemos_d1_mini32\src\A.cpp.o:C:\Users\ppcm\Documents\PlatformIO\Projects\Test/.pio\libdeps\wemos_d1_mini32\TaskScheduler\src/TaskScheduler.h:458: first defined here
.pio\build\wemos_d1_mini32\src\main.cpp.o: In function `Task::getInterval()':
main.cpp:(.text._ZN4Task11getIntervalEv+0x0): multiple definition of `Task::getInterval()'
.pio\build\wemos_d1_mini32\src\A.cpp.o:A.cpp:(.text._ZN4Task11getIntervalEv+0x0): first defined here
.pio\build\wemos_d1_mini32\src\main.cpp.o: In function `Task::getIterations()':
main.cpp:(.text._ZN4Task13getIterationsEv+0x0): multiple definition of `Task::getIterations()'
.pio\build\wemos_d1_mini32\src\A.cpp.o:A.cpp:(.text._ZN4Task13getIterationsEv+0x0): first defined here
.pio\build\wemos_d1_mini32\src\main.cpp.o: In function `Task::getRunCounter()':
main.cpp:(.text._ZN4Task13getRunCounterEv+0x0): multiple definition of `Task::getRunCounter()'
.pio\build\wemos_d1_mini32\src\A.cpp.o:A.cpp:(.text._ZN4Task13getRunCounterEv+0x0): first defined here
.pio\build\wemos_d1_mini32\src\main.cpp.o: In function `Task::setCallback(void (*)())':
main.cpp:(.text._ZN4Task11setCallbackEPFvvE+0x0): multiple definition of `Task::setCallback(void (*)())'
.pio\build\wemos_d1_mini32\src\A.cpp.o:A.cpp:(.text._ZN4Task11setCallbackEPFvvE+0x0): first defined here
.pio\build\wemos_d1_mini32\src\main.cpp.o: In function `Task::setOnEnable(bool (*)())':
main.cpp:(.text._ZN4Task11setOnEnableEPFbvE+0x0): multiple definition of `Task::setOnEnable(bool (*)())'
.pio\build\wemos_d1_mini32\src\A.cpp.o:A.cpp:(.text._ZN4Task11setOnEnableEPFbvE+0x0): first defined here
.pio\build\wemos_d1_mini32\src\main.cpp.o: In function `Task::setOnDisable(void (*)())':
main.cpp:(.text._ZN4Task12setOnDisableEPFvvE+0x0): multiple definition of `Task::setOnDisable(void (*)())'
.pio\build\wemos_d1_mini32\src\A.cpp.o:A.cpp:(.text._ZN4Task12setOnDisableEPFvvE+0x0): first defined here
.pio\build\wemos_d1_mini32\src\main.cpp.o: In function `Task::reset()':
main.cpp:(.text._ZN4Task5resetEv+0x0): multiple definition of `Task::reset()'
.pio\build\wemos_d1_mini32\src\A.cpp.o:A.cpp:(.text._ZN4Task5resetEv+0x0): first defined here
[...]

This is not the complete error because it is too long, but the idea is here

Is there something wrong in the declaration of prototypes of TaskScheduler?
Thanks for your help

@arkhipenko
Copy link
Owner

arkhipenko commented Mar 26, 2022

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

2 participants