multiple definition of local variable in linking 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?
The common practice is to write Arduino libraries using C++ classes:


  The core of the header file consists of a line for each function in
  the library, wrapped up in a class along with any variables you need.


class Morse
{
  public:
    Morse(int pin);
    void dot();
    void dash();
  private:
    int _pin;
};


In this way you can specify what is private (variables and methods only seen within the class) and what is public (variables and methods that can be seen outside the class).  In the given example, the variable called "_pin" is private to the class Morse.

In your case, you would want to make a private class variable called "value".  Because it is private, you are free to re-use the name when not inside the class.