Go Down

Topic: multiple definition (Read 2488 times) previous topic - next topic

ChPr

Hello everybody,

I have an application (séquenceur.ino) that uses UTFT and UTouch libraries.

For this application, I have written a library (ChPComp) that is also using UTFT and UTouch. So I have declared in the file ChPComp.h the variables myGLCD and myTouch :

Code: [Select]
UTFT myGLCD(ITDB32S, 38, 39, 40, 41);
UTouch myTouch(6, 5, 4, 3, 2);


This is the only place where these variables are declared. They are used both in sequence.ino and ChPComp.cpp.

When I compile the application, I have the following error :
Code: [Select]

ChPComp\ChPComp.cpp.o:(.bss.myGLCD+0x0): multiple definition of `myGLCD'
Sequenceur.cpp.o:(.bss.myGLCD+0x0): first defined here
c:/documents and settings/pierre/mes documents/mes téléchargements/arduino-1.5.2/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions
ChPComp\ChPComp.cpp.o:(.bss.myTouch+0x0): multiple definition of `myTouch'
Sequenceur.cpp.o:(.bss.myTouch+0x0): first defined here


I dont know how to exploit this information.

So, how to solve this problem ?

Thank you in advance for your help.

Pierre

Pourquoi faire simple alors qu'il est si facile de faire compliqué !

AWOL

Quote
So I have declared in the file ChPComp.h
Quote
This is the only place where these variables are declared.

But probably included twice?
There's your answer.

PaulS

Quote
So I have declared in the file ChPComp.h the variables myGLCD and myTouch :

The question, of course, is where in that file the variables are defined. And, also, whether the file includes proper include guards to prevent multiple inclusion.

Quote
So, how to solve this problem ?

Write the code correctly. If you need help with that, you need to post the code.
The art of getting good answers lies in asking good questions.

ChPr

Thank you for your replies,

here is the begining of code for each file :

Sequenceur.ino :

Code: [Select]
#include <ChPComp.h>
#include <Constantes.h>
#include <tinyFAT.h>
#include <UTouch.h>
#include <UTFT.h>
#include <DS1307.h>
...


Constantes.h :

Code: [Select]
#ifndef Constantes_h
#define Constantes_h

#define NB_ZONES  6
#define NB_CYCLES  4

#endif


ChPComp.h :

Code: [Select]
#ifndef ChPComp_h
#define ChPComp_h
#include <Constantes.h>

#include <arduino.h>
#include <UTFT.h>
#include <UTouch.h>

UTFT myGLCD(ITDB32S, 38, 39, 40, 41);
UTouch myTouch(6, 5, 4, 3, 2);
...


and finally ChPComp.cpp :
Code: [Select]

#include <Arduino.h>
#include <UTFT.h>
#include <UTouch>
#include <ChpComp.h>

extern uint8_t TinyFont[];
...


Thank you for your help.

Pierre
Pourquoi faire simple alors qu'il est si facile de faire compliqué !

majenko

1. You only define variables in .c or .cpp files, never in .h files.
2. You declare external references to the variables in .h files.

I.e.,
Code: [Select]

UTFT myGLCD(ITDB32S, 38, 39, 40, 41);
UTouch myTouch(6, 5, 4, 3, 2);

should be in a .cpp file, and
Code: [Select]

extern UTFT myGLCD;
extern UTouch myTouch;

should be in the .h file.

ChPr

Thank you "majenko". I applied what you suggested and now it works fine.

I have a lot to learn about C++

Sincerely.

Pierre
Pourquoi faire simple alors qu'il est si facile de faire compliqué !

PaulS

Quote
here is the begining of code for each file :

I was going to say something like "Here is the start of the answer...", but majenko already provided the answer, so I'll resist the temptation to post a smart ass answer.
The art of getting good answers lies in asking good questions.

AWOL


Go Up