Need help to include libs on my project!

Hi all,

I'm working to my project with Arduino DUE but I'm now stopped by this error! I'm using Arduino IDE 1.5.4.

This the includes on my sketch:

#include <SD.h>
#include <SPI.h>
#include <TFT.h>
#include "TB6612FNG.h"
#include "QRE1113AEncoders.h"
#include "GeduinoPINS.h"
#include "Control.h"

This is the Control.h file:

#ifndef Control_h
#define Control_h

#include <SD.h>
#include <SPI.h>
#include <TFT.h>

class  Control{

private:
  
public:

  // Constructor
  Control();
  
  // Show splash screen for given time in milliseconds
  void showSplashScreen(unsigned const long splashDelay);

};

#endif

The problem I have is related to usage of SD, SPI and TFT library. I need to use them on the Control class but if I remove the include for those libraries from my sketch I had a "No such file or directory" error.

In file included from Control.cpp:3:
Control.h:4: fatal error: SD.h: No such file or directory
compilation terminated.

Including those libraries on the sketch seems to fix this problem bit create a new one:

GeduIno.cpp.o: In function `PImage::read32(File)':
/Applications/Arduino.app/Contents/Resources/Java/libraries/TFT/src/utility/Adafruit_GFX.h:296: multiple definition of `PImage::read32(File)'
Control.cpp.o:/Applications/Arduino.app/Contents/Resources/Java/libraries/TFT/src/utility/Adafruit_GFX.h:296: first defined here
GeduIno.cpp.o: In function `PImage::read16(File)':
/Applications/Arduino.app/Contents/Resources/Java/libraries/TFT/src/utility/Adafruit_GFX.h:289: multiple definition of `PImage::read16(File)'
Control.cpp.o:/Applications/Arduino.app/Contents/Resources/Java/libraries/TFT/src/utility/Adafruit_GFX.h:289: first defined here
GeduIno.cpp.o: In function `PImage::loadImage(char const*)':
/Applications/Arduino.app/Contents/Resources/Java/libraries/TFT/src/utility/Adafruit_GFX.h:306: multiple definition of `PImage::loadImage(char const*)'
Control.cpp.o:/Applications/Arduino.app/Contents/Resources/Java/libraries/TFT/src/utility/Adafruit_GFX.h:306: first defined here
GeduIno.cpp.o: In function `Adafruit_GFX::image(PImage&, unsigned short, unsigned short)':
/Applications/Arduino.app/Contents/Resources/Java/libraries/TFT/src/utility/Adafruit_GFX.h:231: multiple definition of `Adafruit_GFX::image(PImage&, unsigned short, unsigned short)'
Control.cpp.o:/Applications/Arduino.app/Contents/Resources/Java/libraries/TFT/src/utility/Adafruit_GFX.h:231: first defined here
collect2: ld returned 1 exit status

Probably this is related to some problem with ifdef/endif on those libs but by now I still no found a solution...

PLEASE HELP ME!!!

Thanks
Ale

PLEASE HELP ME!!!

Stop shouting.

Calmly take your snippets to http://snippets-r-us.com.

Sorry, no more snippets... I added the complete code as attachment!

Thanks
Ale

GeduIno.zip (4.42 KB)

I haven't looked at that Adafruit_GFX.h header but the error message you're seeing looks like a linker error telling you that the method PImage::read32(File) is implemented in two places.

One possible explanation is that the library was implemented poorly and includes method definitions inside the header file. If that was the case then you would end up with duplicate definitions for those methods in every compilation unit that included the header file.

It is a known quirk of the IDE that your sketch .ino file must explicitly include a header file for each library that the sketch uses - even if the .ino file doesn't not depend on any of the declarations in the header file. I haven't tried this, but a possible workaround for that problem may be to enclose the .ino file's #include for the problematic library in #ifdef UNDEF / #endif statements so that it is excluded from compilation. Another possible solution would be to fix the relevant library so that it does not put method definitions in the header file.

Again - this is just based on a guess as to what may be causing the problem.

Hi all,

taking a glance from TFT library, Adafruit_GFX.h file:

[...]It works if this

  • include is used only in one .cpp file in the build (this is the
  • case of most Arduino sketches); if used in multiple .cpp files,
  • the linker may complain about duplicate definitions.

I simply fixed using Adafruit libs from their git hub that has not
this bug (but load image is no so simple like on TFT...).

Thanks for support
Ale