Today I tried to split my current project into some libraries. I did this according to the tutorial in the playground. It works fine as long as I do not define any variables in the .h files.
For example I have put my LCD handling into a separate .h and .cpp file like so:
#ifndef UT_LCD_h
#define UT_LCD_h
#include <LiquidCrystal.h>
#include <inttypes.h>
//create object to control void menu__init() an LCD, number of lines in display=2
//LCD4Bit_mod lcd = LCD4Bit_mod(2);
LiquidCrystal lcd(10, 11, 9, 4, 5, 6, 7);
// function definitions follow here
#endif
The cpp file includes it with
#include "UT_LCD.h"
and the main file includes them with
#include <UT_LCD.h>
When I try to compile this I always get an error
udo@laptop:~/sketchbook/UT$ make
cat build-cli/00_UT.d > build-cli/depends.mk
/usr/bin/avr-gcc -mmcu=atmega328p -lm -Wl,--gc-sections -Os -o build-cli/00_UT.elf build-cli/00_UT.o build-cli/pins_arduino.o build-cli/wiring_analog.o build-cli/wiring.o build-cli/wiring_digital.o build-cli/HardwareSerial.o build-cli/LiquidCrystal.o build-cli/Print.o build-cli/UT_Conversion.o build-cli/UT_Event_buffer.o build-cli/UT_LCD.o
build-cli/UT_LCD.o: In function `lcd__init()':
arduino/UT_LCD.cpp:3: multiple definition of `lcd'
build-cli/00_UT.o:build-cli/00_UT.cpp:2693: first defined here
make: *** [build-cli/00_UT.elf] Fehler 1
Now if code
static LiquidCrystal lcd(10, 11, 9, 4, 5, 6, 7);
instead of
LiquidCrystal lcd(10, 11, 9, 4, 5, 6, 7);
everything works as expected. However the compiled code seems to get longer than it used to be before I split everything.
Since I am not a C Wizard at all I would be very thankful for any hints about what causes this behaviour and the proper solution to get rid of it.