Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

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

  1. #1
    Junior Member
    Join Date
    Aug 2017
    Posts
    18

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

    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

  2. #2
    Junior Member
    Join Date
    Nov 2017
    Posts
    16
    Have you tried just removing the SD library from the audio library in your install to see what happens?

  3. #3
    Senior Member Blackaddr's Avatar
    Join Date
    Mar 2017
    Location
    Canada
    Posts
    126
    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.

  4. #4
    Junior Member
    Join Date
    Aug 2017
    Posts
    18
    Quote Originally Posted by Blackaddr View Post
    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

  5. #5
    Senior Member
    Join Date
    Jul 2014
    Posts
    1,542
    Quote Originally Posted by qcarver View Post
    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)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •