0

I'm currently writing a library application for my Teensy using the Arduino IDE and so far, it has been straight forward enough to do. I have however come across a bit of an odd compilation error that I just can't seem to get my head around. My library includes the well known IRRemote Library in order for me to create what is almost a wrapper library in order to be more specific into the way I need to interact with the IR Remote library. The issue I'm having is with one of the IR Remote library functions:

void  sendRaw(const unsigned int buf[],unsigned int len, unsigned int); 

Although this may seem like a straight forward function to use, the issue i have is with the first argument to the function. I have tried all various ways to pass something to this function paramater but whatever I do, it simply will not compile. Currently i have set a variable

unsigned int bufferToSend[5] = {1,2,3,4,5}; // data is just for example purposes

when i try to call

sendRaw(bufferToSend, 5, 38); // Values are just for example purposes

i get a compiler error of

undefined reference to `IRsend::sendRaw(unsigned int const*, unsigned int, unsigned int)'

Interestingly, if i call the same function directly from inside the Arduino .ino file rather than via my library call, the code compiles and runs perfectly well. Am I missing something blatantly obvious?

CBrown92
  • 21
  • 2
  • You *do* link with the library where the function is defined? And the source file where the function is defined is included in the building of the library? – Some programmer dude Aug 31 '17 at 08:17
  • yes, you make a good point here! in my header file ive included the header the file of the library, but is there something else i need to do within in my library to include it? – CBrown92 Aug 31 '17 at 08:48
  • You need to actually *link* with the actual *library*. The header file defines the interface, not the implementation which should be in a separate library. Do you have a file beginning with `lib` and ending in `.a`? Or something similar? How do you build the library? – Some programmer dude Aug 31 '17 at 08:50
  • yeah you are correct here, I haven't linked against the secondary library i feel rather stupid now. i just need to workout how to link against it in Arduino. I understand how to link against libraries in C/C++, i guess i thought the Arduino compiler handled all of that automatically, but clearly I'm wrong haha! – CBrown92 Aug 31 '17 at 08:55
  • It turns out this is a common problem; getting a custom library to build on top of pre-exisiting libraries and it looks like there are writeups on how to do this. – CBrown92 Aug 31 '17 at 08:59

1 Answers1

1

With the help of 'Some programmer dude', I was able to resolve this issue. As it was quite rightfully pointed out, I wasn't actually linking against the external library from within my library. having worked with library linking previously, I know this is absolutely fundamental, however with Arduino and its nature, it compiles libraries that are linked against "on-the-go" when you include from the Arduino script and therefore i fell victim to thinking it would be the same in a custom library. I came across a very good write-up of my exact problem below that provides an excellent explanation to some of the Arduino "smoke and mirrors" magic and how to get round the issue I've faced here.

Advanced Arduino – Including Multiple Libraries In Your Project

CBrown92
  • 21
  • 2