A ton of errors when including my own library...

Hello

I created two libraries for myself, one for controlling a LCD user interface (LCDUI) and the other for controlling an RFID reader (EZ522).

LCDUI has one class, UI, and is made of two files, ui.h and ui.cpp.
EZ522 does also only have one class, RFID, and is made of two files EZ522.h and EZ522.cpp

While developing the libraries, I had the .h and .cpp files of both libraries in the same folder as a test program so I could easily test and debug the library.

Everything worked fine.

Then I put the h and cpp files of both libraries into a .zip file, added keywords.txt for syntax coloring, then I added the library in the IDE. Of course I replaced all the

#include "something.h"

by

#include <something.h>

.

I then restarted the IDE, reopened the sketch and, of course, no syntax coloring. I have no idea if I did a mistake in the keywords.txt file or if something wrong happened when adding the library, and if it could have something to do with my problem. (Who knows?)

Then I compiled the sketch and, guess what, it did not work at all. Despite everything worked perfectly when the files were in the same folder, the compiler insulted me with a ton of errors, like:

libraries\LCDUI\ui.cpp.o (symbol from plugin): In function `UI::getKeystroke()':

(.text+0x0): multiple definition of `UI::splash(char*, double, char*, int, int, bool, int)'

sketch\ui.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\LCDUI\ui.cpp.o (symbol from plugin): In function `UI::getKeystroke()':

(.text+0x0): multiple definition of `UI::splash(char*, double, char*, char*, int, char*, int, int, bool, int, int, bool, int)'

sketch\ui.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\LCDUI\ui.cpp.o (symbol from plugin): In function `UI::getKeystroke()':

(.text+0x0): multiple definition of `UI::prompt(char*, char*)'

sketch\ui.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\LCDUI\ui.cpp.o (symbol from plugin): In function `UI::getKeystroke()':

(.text+0x0): multiple definition of `UI::prompt(char*, double, char*, int, bool, int)'

sketch\ui.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\LCDUI\ui.cpp.o (symbol from plugin): In function `UI::getKeystroke()':

(.text+0x0): multiple definition of `UI::prompt(char*, double, char*, char*, int, char*, int, bool, int, int, bool, int)'

sketch\ui.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\LCDUI\ui.cpp.o (symbol from plugin): In function `UI::getKeystroke()':

(.text+0x0): multiple definition of `UI::input(char*, float, float, float, float, char*, int, bool, int)'

sketch\ui.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\LCDUI\ui.cpp.o (symbol from plugin): In function `UI::getKeystroke()':

(.text+0x0): multiple definition of `UI::inputRestricted(char*, int*, int, int, char*, int, bool, int)'

sketch\ui.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\LCDUI\ui.cpp.o (symbol from plugin): In function `UI::getKeystroke()':

(.text+0x0): multiple definition of `UI::inputRestricted(char*, float*, int, int, char*, int, bool, int)'

sketch\ui.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\LCDUI\ui.cpp.o (symbol from plugin): In function `UI::getKeystroke()':

(.text+0x0): multiple definition of `UI::menu(char*, char**, int*, int, int)'

sketch\ui.cpp.o (symbol from plugin):(.text+0x0): first defined here

libraries\LCDUI\ui.cpp.o (symbol from plugin): In function `UI::getKeystroke()':

(.text+0x0): multiple definition of `UI::inputChar(char*, char*, int)'

sketch\ui.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
Erreur de compilation pour la carte Arduino Duemilanove or Diecimila

In my code, some functions are actually declared several times, like that:

void disp(char top [], char bottom [] = "");//Displays two char arrays, on the top and bottom lines of the display.
  void disp(char title [], double value, char unit [] = "", int minDigits = 0, bool showDecimal = false, int base = DEC);
  void disp(char topTitle [], double topValue, char topUnit [], char btmTitle [], int btmValue, char btmUnit [], int topMinDigits = 0, bool topShowDecimal = false, int topBase = DEC, int btmMinDigits = 0, bool btmShowDecimal = false, int btmBase = DEC);

But I don’t think this is the problem, because i have the

multiple definition of

for each and every function of both libraries.

I’ve googled this but i didn’t really understood anything of what I read because I’m not good at programming. Or I don’t have enough knowledge of C++ compiling and object oriented programming to understand it.

Any help would be greatly appreciated. Thanks in advance. I’m sure I made a stupid mistake…

Code is here:

Code

Sorry but the forum won't let me post that much code.

Multiple definition means the functions are defined twice.
Did you accidentally leave your library files in your sketch folder? Any .cpp file in the sketch folder will get compiled with your sketch. If the library also gets compiled those two are declaring the same functions.

atmel9077:
Any help would be greatly appreciated. Thanks in advance. I’m sure I made a stupid mistake…

I would come at this from the other end.

If the code is only for my own use I would not bother making it into a library.

…R

Then I put the h and cpp files of both libraries into a .zip file, added keywords.txt for syntax coloring, then I added the library in the IDE

Personally I would have created the folder in the libraries folder and added the files myself. Where did the installation process put the library files ?

void disp(char top [], char bottom [] = "");//Displays two char arrays, on the top and bottom lines of the display.
  void disp(char title [], double value, char unit [] = "", int minDigits = 0, bool showDecimal = false, int base = DEC);
  void disp(char topTitle [], double topValue, char topUnit [], char btmTitle [], int btmValue, char btmUnit [], int topMinDigits = 0, bool topShowDecimal = false, int topBase = DEC, int btmMinDigits = 0, bool btmShowDecimal = false, int btmBase = DEC);

Did you write the code like that ?

Thank you for your replies. I did not realize that #include "something.h" checks in BOTH the folder and the libraries folder.

Robin2:
If the code is only for my own use I would not bother making it into a library.

Even if it's for my own use, I prefer having it as a library so if I want to add functionnality, all sketches using the library will benefit it.

UKHeliBob:
Did you write the code like that ?

What do you mean by that? Should I give a different name to each prototype of each function?

atmel9077:
Even if it's for my own use, I prefer having it as a library so if I want to add functionnality, all sketches using the library will benefit it.

I guess I am more cautious. The way I look at it if the library changes it breaks all the older programs that rely on it. :slight_smile:

But, each to his own.

...R

Now it’s fixed. Even after removing the files from the directory it would not work. But after I restarted the IDE it worked. And I found that according to the C++ standard, the meaning of #include “” and #include <> is implementation-defined, so next time I’ll be careful!