Redefinition variable in header file \

mikroC, mikroBasic and mikroPascal PRO for Microchip’s 32-bit PIC MCUs
Post Reply
Author
Message
ciccioc74
Posts: 32
Joined: 30 Jul 2007 10:09
Location: sicilia

Redefinition variable in header file \

#1 Post by ciccioc74 » 02 Nov 2017 13:56

Hi i'm new of mikroC pro
i use rev 4.0.0. for pic 32
i have a error with my very simple program
main.c

Code: Select all

#include "NewUnit_0.h"
void main() {
   int i=0;
   pippo=0;
}
secondFile.c

Code: Select all

#include "NewUnit_0.h"
void temp(){
   pippo=1;

}
NewUnit_0.h

Code: Select all

#ifndef EXAMPLE_H
#define EXAMPLE_H

extern float pippo=32;

#endif /* EXAMPLE_H */
when i compile i have a error
4 355 Redefinition of 'pippo [secondFile.c] pippo' already defined in 'multifile2.c' secondFile.c
0 355 Redefinition of '?ICS_pippo [secondFile.c] ?ICS_pippo' already defined in 'multifile2.c' secondFile.c


my question:
how can i use a variable from multiple files?
i wish a simple example
tanks

ciccioc74
Posts: 32
Joined: 30 Jul 2007 10:09
Location: sicilia

Re: Redefinition variable in header file \

#2 Post by ciccioc74 » 02 Nov 2017 13:57

thi is the project
Attachments
Nuova cartella (2).rar
(30.03 KiB) Downloaded 180 times

PeDre
Posts: 27
Joined: 04 Oct 2010 07:16
Location: Austria

Re: Redefinition variable in header file \

#3 Post by PeDre » 02 Nov 2017 14:25

I think you're missing the definition of the variable.

main.c

Code: Select all

#include "NewUnit_0.h"

float pippo=32;

void main() {
   int i=0;
   pippo=0;
}

ciccioc74
Posts: 32
Joined: 30 Jul 2007 10:09
Location: sicilia

Re: Redefinition variable in header file \

#4 Post by ciccioc74 » 02 Nov 2017 14:49

tank for the reply but the definition is in the header file...

PeDre
Posts: 27
Joined: 04 Oct 2010 07:16
Location: Austria

Re: Redefinition variable in header file \

#5 Post by PeDre » 02 Nov 2017 16:27

The header file contains the declaration.
The variable is defined at one place, but declares it wherever you use it.

Refer to the help file under "extern".

ciccioc74
Posts: 32
Joined: 30 Jul 2007 10:09
Location: sicilia

Re: Redefinition variable in header file \

#6 Post by ciccioc74 » 02 Nov 2017 16:52

ok the correct version
main

Code: Select all

#include "NewUnit_0.h"
float pippo=32
void main() {
   int i=0;
   pippo=0;
}
secondFile.c

Code: Select all

#include "NewUnit_0.h"
void temp(){
   pippo=1;

}
NewUnit_0.h

Code: Select all

#ifndef EXAMPLE_H
#define EXAMPLE_H

extern float pippo;

#endif /* EXAMPLE_H */


User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: Redefinition variable in header file \

#7 Post by filip » 03 Nov 2017 15:50

Hi,

Try the corrected project in the attachment.

Regards,
Filip.
Attachments
Nuova cartella (2).rar
(1.62 KiB) Downloaded 300 times

ciccioc74
Posts: 32
Joined: 30 Jul 2007 10:09
Location: sicilia

Re: Redefinition variable in header file \

#8 Post by ciccioc74 » 03 Nov 2017 16:22

grazie

Post Reply

Return to “PIC32 PRO Compilers”