I am trying to make my own library and it uses some local variables with the same name as some variables in ino. Compiler complains about it. I stripped it to (nonsence but simple) example
mylib.h:
#ifndef MYLIB_H
#define MYLIB_H
int doit();
#endif
mylib.cpp:
#include "mylib.h"
int value;
int doit(){
return value++;
}
example.ino:
#include "mylib.h"
int value;
void setup(){
value=3;
pinMode(13,OUTPUT);
}
void loop() {
digitalWrite(13,(value==doit()) );
}
compiling:
$ make
/usr/bin/avr-gcc -Os -Wl,--gc-sections -mmcu=atmega328p example.o mylib.o .lib/arduino.a -lm -o example.elf
mylib.o:(.bss.value+0x0): multiple definition of `value'
example.o:(.bss.value+0x0): first defined here
collect2: error: ld returned 1 exit status
/home/gilhad/GIT/HW/Arduino/minipro//../Arduino.mk:436: recipe for target 'example.elf' failed
make: *** [example.elf] Error 1
I am not usint the value
in the .h
file, so why it collides with similary named variable from another module?
Should not be it private to the module until exposed via .h
file?
I
do not know something, which I should know. And I am planning to write much complicated projects, so I want to know not only how make things nice, but also how it works under hooks when I want to poke really deep :)