dlopen() won't load my dylib, help!

Discussion in 'Mac Programming' started by MultiPlatform, May 7, 2010.

  1. MultiPlatform macrumors newbie

    May 7, 2010
    I'm a OSX newbie so please be kind. dlopen() won't load a dylib, dlerror() returns:

    Unable to load /path/to/my.dylib. dlopen(/path/to/my.dylib) failed: dlopen(/path/to/my.dylib): no suitable image found. Did find: /path/to/my.dylib: unknown file type, first eight bytes: 0x21 0x3c 0x61 0x72 0x63 0x68 0x3E 0x0A

    I believe this means something is wrong with my dylib, but I don't know what. I also tried creating the lib as a bundle by changing the project values shown below, but I still get the same error:

    MACH_O_TYPE mh_bundle

    Please point me in the right direction. We need to load the lib at runtime because we will load a different lib depending on runtime parameters and we try to use dlopen() to keep code identical across platforms (Solaris, Trusted Solaris, Linux, OSX) but replacing dlopen() with a different function call will be fine in this case as long as we can load the lib at runtime. Please help!
  2. Cromulent macrumors 603


    Oct 2, 2006
    The Land of Hope and Glory
    Did you compile the library for the same architectures as the client app? Did you compile the library targeting the same or lower base Mac OS X SDK?

    As for the rest, no code, no help.
  3. chown33 macrumors 604

    Aug 9, 2009
    0x21 0x3c 0x61 0x72 0x63 0x68 0x3E 0x0A is: !<arcf>\n

    That is not the magic number of a dylib.

    Paste the following command into Terminal, then post the output:
    file /path/to/my.dylib
    Also, identify what your OS version is, and what you're using to compile your dylib. If the latter is Xcode, give the specific version.

    If using Xcode, then what project template did you use to create the dylib project? If you chose the wrong one, the simplest remedy may be to start a new project of the right kind, and move your source files to it.

    Finally, what were your project build options when the 0x21 0x3c 0x61 0x72 0x63 0x68 0x3E 0x0A error was produced?
  4. MultiPlatform thread starter macrumors newbie

    May 7, 2010
    Thank you very much for your replies, I'll try to answer your questions:

    (1) Yes all of my binaries are compiled for the same architecture (main executable and libraries). I created the project by copying a working "dynamic library" target, then changing the source files and changed the output type (Mach-O type) to bundle. The call to dlopen() to load this lib happens inside the dynamic library, is that itself a problem?

    (2) Output of file /path/to/my.dylib: my.dylib: current ar archive random library

    I'm not sure why this doesn't say "Mach-O bundle i386" because my project is set to output a "bundle". Maybe changing the Mach-O type alone isn't enough?

    (3) I'm using xcode 3.2.1 x86, base SDK 10.5, gcc 4.2, deployment target OSX 10.5, dynamic link to libstdc++, Mach-O Type Bundle,

    (4) To create the project I right clicked a working target of type dynamic library and selected "Duplicate", then I changed the source files, output name and Mach-O type to "bundle".

    (5) Project options are as shown above, but let me know if you would like anything additional.

    I will try starting a new project of type bundle, though I'm still not sure why this one isn't working..
  5. MultiPlatform thread starter macrumors newbie

    May 7, 2010
    I've figured out the problem. Even though I changed the setting in xcode to specify output type "dynamic library" or "bundle", xcode was ignoring the setting. Starting a new BSD dynamic library project solved the issues I was seeing. Thanks for the help!
  6. chown33 macrumors 604

    Aug 9, 2009
    I'm glad it worked out.

    There can be multiple build settings in a project that affect what Xcode does. The hierarchy is Target Setting then Project Setting. It's not uncommon for Xcode newbies to change the Project Setting, and not change the Target Setting, and the latter is the one that takes effect.

    Here's a somewhat older article that describes this:

    The "Build Setting Precedence" section gives the entire precedence hierarchy. Some of the window screenshots aren't identical to Xcode 3.2, but the overall description and images are still correct.

    Note the Target Settings window will titled "Target xx Info", while a Project Settings window will be titled "Project xx Info". I know a lot of people don't completely read title-bars, but it's crucial here because the windows look very similar.

    Newer docs on the build system:

Share This Page