-
I'm helping someone with an Arduino project that incorporates several devices. One of the input devices is an IR remote. I'm attempting to build a library for that project. Part of the library makes use of an IRrecv. I have run into what seems like an unending series of linker problems of the multiple definition or undefined reference variety, depending on the code experiments I've run. I have read "Using the new *.hpp files" section of https://github.com/Arduino-IRremote/Arduino-IRremote#does-not-workcompile-with-another-library and have spent considerable time studying the source code. My understanding is that USE_IRREMOTE_HPP_AS_PLAIN_INCLUDE separates the declaration from the definition of class IRrecv and the instantiation of IrReceiver. If you define USE_IRREMOTE_HPP_AS_PLAIN_INCLUDE, you get only the declaration. If undefined, you get declaration, definition and instantiation of IrReceiver. Define USE_IRREMOTE_HPP_AS_PLAIN_INCLUDE when you're writing library code that only needs the declaration. Don't define it in a .ino when you need both the declaration and the definition in order to compile and link. At least that's my impression. Could well be wrong! But I can't seem to build a .ino successfully due to linking problems. Here's the closest I've gotten: /examples/link/link.ino: #define INCLUDE_FROM_INO simple S; void setup() { void loop() { /src/vscope.h: /src/simple.h: class simple { /src/simple.cpp: simple::simple() {} void simple::read() { Short Explanation: This compiles, but linking fails with message "undefined reference to `_ZN6IRrecv6decodeEP14decode_results'", and a reference to the _rcvr.decode() statement in simple::read(). I'm using Arduino IDE-1.8.19 on a Gentoo linux system, programming for an Arduino nano. My development environment otherwise produces working code for the nano, and the IRremote example SimpleReceiver works fine. So... what am I misunderstanding/doing wrong? Is it possible for a library to use an IRrecv as a client? Thanks for your help! John Blinka |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
No, you are right! 😀 But please, do not use deprecated functions, use _rcvr.decode(); |
Beta Was this translation helpful? Give feedback.
-
Sent from Proton Mail for iOS
On Tue, Aug 15, 2023 at 4:25 AM, Armin ***@***.***(mailto:On Tue, Aug 15, 2023 at 4:25 AM, Armin <<a href=)> wrote
But please, do not use deprecated functions, use _rcvr.decode();
I extended the [IRremoteExtensionClass](https://github.com/Arduino-IRremote/Arduino-IRremote/blob/master/examples/IRremoteExtensionTest/IRremoteExtensionClass.cpp) example. to cover your problem and I get no errors.
—
With your guidance, my library works perfectly now.
I don’t know how I came to use the interface I posted, but it was older code that had worked previously. I’ve looked at examples/SimpleReceiver in more detail just now and see how to do it properly.
Thank you!
John
|
Beta Was this translation helpful? Give feedback.
No, you are right! 😀
But please, do not use deprecated functions, use _rcvr.decode();
I extended the IRremoteExtensionClass example. to cover your problem and I get no errors.