Including any file in Audio library causes entire Audio library to be included

Status
Not open for further replies.

qcarver

Member
Hello,

My project leverages STL5000 audio shields and I sample audio data. I included the files I need from the audio library for i2S , the shields, and patchCords without including the whole <Audio.h>. This is because I do NOT wish to include the disk stuff (in fact it gets in the way of another disk library I use instead - Bill Greimans SdFat 1.0.3).

What I observe is that the compiler links in the whole Audio library, which includes the SD library (undesirable for me).

Is there a way to stop this (automatically including the SD library) from happening?

My includes:

Code:
#include "input_i2s_quad.h"
#include "output_i2s_quad.h"
#include "control_sgtl5000.h"
#include "record_queue.h"

and in another file:

Code:
#include <SPI.h>
#include "SdFat.h"
#include "FreeStack.h"


the entire code (5 files) is here should that be helpful.

snippets from my output:

Code:
Using library SPI at version 1.0 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\SPI 
Using library SdFat at version 1.0.3 in folder: C:\Program Files\Arduino\libraries\SdFat 
Using library Audio at version 1.3 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\Audio 
Using library Wire at version 1.0 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\Wire 
Using library SD at version 1.1.1 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\SD 
Using library SerialFlash at version 0.5 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\SerialFlash
 
Have you tried just removing the SD library from the audio library in your install to see what happens? :)
 
I presume you are using the Arduino IDE. In order to make normally complicated things (like compiling and linking dependencies) work auto-magically, it does some things that get in the way of more advanced user needs.

Most people hack it and move the original out of the way, and make a custom library containing only what they need.

Another (better) approach but far more difficult is to kick off the Arduino IDE training wheels and move to a proper build environment where you (not the IDE) decide exactly what you include and do not. This post mentions a couple alternatives:
http://tutorial45.com/arduino-ide-alternative/

If you are making a project just for yourself, choose which ever path gets the results you want with the least effort. If you want to share your project with others to use, then I'd say it really should work with Arduino IDE, and minimal to no hacking.
 
Most people hack it and move the original out of the way, and make a custom library containing only what they need.

And the winner is "Blackaddr". Thank you. So lessons learned I put in a comment at the top of my ino which now says:

Code:
    notes: In Arduino land, the entire library is included when you include any
    declaration from it. Therefore, all of Audio.h will be included. PlayRawFile
    incudes SD.h which includes SD library this has global name collisions with SDFat. 
    Work around is to subset the Audio library so that it doesn't have a file which includes
    SD.h then put that library in your sketchbook's library folder. That folder will override
    the definition in the Application library folder and keep colisions from happening
 
And the winner is "Blackaddr". Thank you. So lessons learned I put in a comment at the top of my ino which now says:

Code:
    notes: In Arduino land, the entire library is included when you include any
    declaration from it. Therefore, all of Audio.h will be included. PlayRawFile
    incudes SD.h which includes SD library this has global name collisions with SDFat. 
    Work around is to subset the Audio library so that it doesn't have a file which includes
    SD.h then put that library in your sketchbook's library folder. That folder will override
    the definition in the Application library folder and keep colisions from happening

Not entirely correct, AFIK, (depending on what you mean by included).
The .h files are included (as audio.h does include them) and this may generate a lot of problems.

library files are compiled (waste of time)

BUT the routines are not linked in (objects are not included), so hex file has only used routines


My approach: use empty *ino file (to trick Arduino) and do all my programming in *cpp file, with explicit includes (following c/c++ programming practice)
 
Status
Not open for further replies.
Back
Top