Unable to declare variable in a library that doesn't have a class: multiple definition of the variable I have created a library Lib that doesn't have a class. I want this library to have a variable that can be accessed from outside. The way I would go about this is to just declare them in the header file.

However, if I do this like so:

int myVariable = 1;


with the .cpp-file containing only

#include "Lib.h"


I get this error message when compiling an empty sketch that includes this library:


  multiple definition of `myVariable'


and for some weird reason


  Multiple libraries were found for "Lib.h"


on top of that (although, this is something I have encountered before - when there is some error during the compilation, this error may come alongside it, even though there are no multiple libraries; it goes away when the other compilation errors are resolved aswell).

What is causing that error and how to resolve it?
In Lib.h you should declare an

extern int myVariable;


In Lib.cpp you can define it once

#include "Lib.h"
int myVariable=123;
...