Blog

Avoiding duplicate symbol issues when using common utilities within a static library

Screen Shot 2012 04 15 at 14 03 28I’m working on two projects right now that have static library products, to be given to other developers to use in their projects: Audiobus and The Amazing Audio Engine. In both cases, I’m making quite heavy use of my circular buffer code, TPCircularBuffer, which would result in duplicate symbol errors if the static library were linked with another project that used it.

In case the solution was useful to others, here’s how I worked around it: Use the preprocessor to rename the symbols automatically during the build phase.

This is done by adding a series of -DOldSymbol=NewSymbol flags to the ‘Other C Flags’ build setting – like -DTPCircularBuffer=ABCircularBuffer, for instance.

No more symbol conflicts.

Tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

3 Comments

  1. Rog
    Posted April 15, 2012 at 4:18 pm | Permalink

    …but duplicating the code and making the build and debugging difficult to understand. Why not ship a third library with the shared code or a single library with both dependencies and the buffer.

    • Posted April 15, 2012 at 4:56 pm | Permalink

      Rog: Cleanliness and ease of use, and conflict avoidance. What if your project already uses an older version of one of the dependencies, or one of the other utilities the library relies upon? Suddenly, dependency management gets incredibly complicated and annoying.

      I don’t like the idea of forcing users to deal with that kind of complexity. At least, I wouldn’t like that, as a user.

      I don’t really see how doing this makes the build hard to understand, or how it complicates debugging =)

  2. Alex
    Posted April 15, 2012 at 7:07 pm | Permalink

    Great stuff. Thanks! I ran into this exact same problem using your library template. Was desperate to avoid giving things ridiculous names to the avoid the issue. How I miss Java packages :p.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use Markdown (surround code in `back-ticks`), or these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting