Template for Arduino libraries using archives?

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I recently figured out that by default Arduino only creates an archive (.a) for the core, and not for any libraries.  Despite almost all C developers being familiar with the convention of combining .o files in to a .a, for the Arduino IDE all .o's built from a library are included on the link line.

I made a UART library that has optional support for interrupt-driven receive.  By putting the rx_data_ready() function in the same .o as the ISR (where the vector is defined), and linking the library .a, the ISR only gets installed if the rx_data_ready() function is used.  When I tried using the library in the Arduino IDE, I ran into the problem.  With the Arduino library build process, the ISR code gets included even if it is never used.

 

I see from the arduino libary specs that it is possible to create archive files.

https://arduino.github.io/arduin...

 

My tolerance for learning Arduino internals is rather limited, as I have to suppress the impulse to bang my head against the wall every time I read another stupid way it does things. :-)

Is anyone aware of a reasonably simple and well written Arduino library I can use as a template?

 

I have no special talents.  I am only passionately curious. - Albert Einstein

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 3

ralphd wrote:
simple and well written Arduino library

Isn't that an oxymoron?

David (aka frog_jr)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Does arduino.cc have a "developers" area - as opposed to the "user" areas - for this kind of question ?

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

awneil wrote:

Does arduino.cc have a "developers" area - as opposed to the "user" areas - for this kind of question ?

Even if it did, I'm not welcome there.  I got banned from the forums several years ago after questioning the honesty/ethics of Marchese Banzi.

 

I have no special talents.  I am only passionately curious. - Albert Einstein

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

was that in the "Arduino Wars" ... ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
was that in the "Arduino Wars" ... ?

No, I think that was in "Arduino strikes back!"...  

 

 

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've found I've wasted more time in the Arduino forum than the benefits I reaped from it. 

 

FIY, since it's C++ I write my arduino libraries as a single .hpp file, which helps me get the inlining and code optimization properties I want.
I would have expected unused methods would get stripped by the linker even if they're defined in a .cpp file and compiled in a separate .o.

TBH IDK if the linker would nuke unused methods from a .a... When you compile a static binary there's no reason to keep unused methods, nor keep them relocatable. hmmm...

My GitHub (FAB_LED bitbang for ws2812, DigitalIO, SerialMenu...).
I make portable, code optimized Arduino libraries as a hobby and use AtTiny85 the most for my builds.
I am a burner and an OS and systems programmer by trade.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

could it be the ISR stays because you have a function pointer that doesn't optimize away when you compile a program using your library? Protect its use by a program constant?

My GitHub (FAB_LED bitbang for ws2812, DigitalIO, SerialMenu...).
I make portable, code optimized Arduino libraries as a hobby and use AtTiny85 the most for my builds.
I am a burner and an OS and systems programmer by trade.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sonyhome wrote:

could it be the ISR stays because you have a function pointer that doesn't optimize away when you compile a program using your library? Protect its use by a program constant?

No.  The vectors are all weakly defined in crt0, so any .o (not contained within a .a) that defines a vector will be preferred and get linked in.  When it is in a .a, the linker only pulls in .o's to resolve undefined references.  A good example of how it works would be to look at how __do_clear_bss and __do_copy_data only get linked in when needed.

 

I have no special talents.  I am only passionately curious. - Albert Einstein

 

Last Edited: Sun. May 3, 2020 - 12:12 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sonyhome wrote:

could it be the ISR stays because you have a function pointer that doesn't optimize away when you compile a program using your library? Protect its use by a program constant?

 

I think this explains it better than I could.

https://eli.thegreenplace.net/20...

I have no special talents.  I am only passionately curious. - Albert Einstein