I was wondering if anyone could give me a helping hand. I'm working on an Arduino shield and I'm creating a library for it in order to interface with it.
I would like to use the SoftwareSerial as well as a 3rd party library inside my library. However, when I compile, I get the following errors:
warning: SoftwareSerial.h: No such file or directory
'SoftwareSerial' does not name a type
Seem like it's not linking up.
Now the 3rd party library is specifically Rogue Robotics' Tone library. That one I can include fine without any compile errors. But when I call Tone.begin(), I get the following:
undefined reference to `Tone::begin(unsigned char)
This is how I declare the libraries in my header file.
This is how I declare the libraries in my header file.
And this is how I try to instantiate them in my cpp file.
And your sketch? I'm guessing that you're trying to hide the use of SoftwareSerial and the other library from the sketch. The sooner you get over the idea that that is a good idea (or even possible), the happier you'll be.
I know I'm asking for trouble trying to do this, but from a user's perspective it would be great if the library included any other libraries that are needed. At this point, I just wanna know if it's even possible!
Hello.
I have the same problem.
For the accuracy of the experiment I copied the code above comrade mikevanis, exclude tone.h. My Arduino IDE 1.0.5 shows an error:
D:\Program Files (x86)\Arduino\libraries\Gamer/Gamer.h: In constructor 'Gamer::Gamer()':
D:\Program Files (x86)\Arduino\libraries\Gamer/Gamer.h:10: error: no matching function for call to 'SoftwareSerial::SoftwareSerial()'
D:\Program Files (x86)\Arduino\libraries\SoftwareSerial/SoftwareSerial.h:83: note: candidates are: SoftwareSerial::SoftwareSerial(uint8_t, uint8_t, bool)
D:\Program Files (x86)\Arduino\libraries\SoftwareSerial/SoftwareSerial.h:48: note: SoftwareSerial::SoftwareSerial(const SoftwareSerial&)
sketch_oct26a.ino: At global scope:
sketch_oct26a.ino:4: note: synthesized method 'Gamer::Gamer()' first required here
At this point, I just wanna know if it's even possible!
Yes, it is possible if the sketch includes all the same header files.
If not, then you need to use something other than the IDE to compile your code.
Add
#include <SoftwareSerial.h>
to your sketch. Then the IDE will be able to compile the code.
This is 100% correct.
The IDE builds his link build path based on the includes in the .ino file only.
So having the includes in your include file is not enough.
Best regards
Jantje
This is trying to create an instance of the SoftwareSerial class, but, obviously it can't because the SoftwareSerial class does not, unfortunately, have a no argument constructor.
One solution:
SoftwareSerial *serial;
serial = new SoftwareSerial(RX, TX);
Then, use serial->, instead of serial. to access member of the SoftwareSerial class.