Xcode library loading oddities

Discussion in 'Mac Programming' started by printz, Apr 5, 2014.

  1. printz macrumors regular

    Joined:
    Dec 23, 2012
    #1
    There's something strange with Xcode going on. If I have many .dylib and .a libraries in a common place (like /opt/local/lib), and if I tell it to link with libopencv and libSDL2 (for example) from that folder, at run-time during initialization it will warn me in the console that some function was found both in libSDL.dylib (from same folder) and libSDL2.dylib (and the choice will be undefined), despite me never choosing to link with libSDL in the Xcode project. What is going on? Is it trying to link with all libraries from /opt/local/lib? Can I fix this issue, preferably without moving libraries to a local folder or using an external build tool (unless Xcode works seamlessly with external build tools)?

    If all else fails, what C++ IDEs would you recommend? Is JetBrains AppCode for C++ too, not just Objective-C? Otherwise I guess I can try command-line build tools like SCons or Make.
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    First, find out exactly which libraries are being used by your executable. The tool for that is 'otool'. Try this Terminal command:
    Code:
    otool -L  /path/to/your/executable
    
    It should list all the dylibs it directly references. Post the output.

    If 'otool' isn't installed (it should be part of command-line tools), then install the command-line tools and try again.


    Second, it's possible your executable isn't referencing libSDL.dylib, but some other dylib you're using is. That is, a transitive library reference, yourApp -> someLib -> libSDL.dylib.

    A transitive reference through another library may be fixable withou;t recompiling anything, but the hard part will probably be finding it. To do that, we need a list of exactly what libs your executable directly references. From there one can search for transitive references. Without that list, which is what otool produces, it would be far more difficult.


    Third, do you use libSDL.dylib for anything? What are the differences between libSDL.dylib and libSDL2.dylib? Are they intended to be different things, with a different API, or is libSDL2.dylib intended to replace libSDL.dylib,possibly as a superset? In other words, explain the logical relationship between the two libs. This will go a long way to clarifying a possible strategy for replacing a transitive reference.
     
  3. Madd the Sane macrumors 6502

    Madd the Sane

    Joined:
    Nov 8, 2010
    Location:
    Utah
    #3
    SDL2 has more APIs and changes how SDL manages windows/OpenGL contexts.

    The good thing about Mach-0's shared libraries is that if library A uses a function in library B, while program a uses a function from library A, and a function from library C that has the same symbol as library B, they will use the respective versions.

    Objective C, however, is a weak reference language, making the use of that really hard, if not impossible. So when two binaries (whether they be executables, libraries, bundles, or any combination thereof) has two classes with the same name, it can cause problems. If the classes are the same, then there will be little-to-no problems.

    I don't know how different those two classes are, though. One version could have different functions implemented. I have heard that the SDL developers are working on a compatibility library that will let SDL 1.2 code use SDL2.
     

Share This Page