Go Down

Topic: Strange error (Read 2 times) previous topic - next topic

billroy

I believe this is a frequently asked question.   Here's my understanding of the answer.

To use one library from another, it is necessary to include both libraries from the sketch, and make any references to the libraries from sketch-based code.  (This can be awkward…)  The Bitlash examples that include other libraries are structured this way: https://github.com/billroy/bitlash/tree/master/examples and yes it can lead to ugly things like passing around function pointers.

I've had no luck including one library directly in another.  I hope someone will correct my understanding if it's wrong.

-br

BenMcLean

billroy, I may be misunderstanding you, but are you saying it can't be done? Which basically means that the language in the Arduino software is not really C++, but is some craptarded subset of C++?

billroy

Well first of all, all I'm sayin' is I don't know how to do it directly, but have found a workaround, and I believe if you search the forum you will find other threads on the subject.

I think your characterization might be a little harsh.  This is a feature of the Arduino build environment, not C++.  Building sketches based on libraries is easy, in this system.  Building libraries that cross-reference each other: I don't know how.

But don't give up.  Your post says you've put the BMSerial library in the Arduino libraries/ folder in the usual place.  Is there any reason you can't put it directly into your library folder and ship it with your library?  I've found #includes work within the library's folder.

(I am still puzzling about why this would be causing a relocation error…)

-br

BenMcLean

#8
Dec 07, 2012, 02:28 am Last Edit: Dec 07, 2012, 02:32 am by BenMcLean Reason: 1
Oh sure I can throw it in my library folder, since this library I'm writing isn't going to get distributed.

But here is some interesting information I have come up with.

If I take all the members of this library and put them into a sketch with the private data members as global variables and the public methods as loose functions, it builds fine and avr-size says this:
Code: [Select]
AVR Memory Usage
----------------
Device: Unknown

Program:     666 bytes
(.text + .data + .bootloader)

Data:          9 bytes
(.data + .bss + .noinit)


But the above sketch with library produces these results:
Code: [Select]
AVR Memory Usage
----------------
Device: Unknown

Program:    4622 bytes
(.text + .data + .bootloader)

Data:        123 bytes
(.data + .bss + .noinit)


As I understand how compilation and linking works, there should not be much of a significant difference between the two versions except for two additional ints. So something is really screwed up about the way Arduino builds.

BenMcLean

OK throwing BMSerial in the same folder with my library lets me get rid of the #include "BMSerial.h" in my sketch. But it produces the same cryptic error message.

Go Up