Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8899793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:56:40+00:00 2026-06-15T00:56:40+00:00

I have a library libni on OSX I’m trying to open using dlopen(), and

  • 0

I have a library libni on OSX I’m trying to open using dlopen(), and it can’t seem to resolve the dependencies to another dlopen()’d library.

Lets not get into why you shouldn’t use dlopen(); suffice to say, I have to use it in this circumstance.

Anyway, so this is otool -L on libni.dylib:

lib/libni.dylib:
  libni.dylib (compatibility version 0.0.0, current version 0.0.0)
  libn.dylib (compatibility version 0.0.0, current version 0.0.0)
  /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
  libzlib.dylib (compatibility version 0.0.0, current version 0.0.0)
  libpng.dylib (compatibility version 0.0.0, current version 0.0.0)
  liblua.dylib (compatibility version 0.0.0, current version 0.0.0)
  libSDL2.0.dylib (compatibility version 0.0.0, current version 2.0.0)
  libstb.dylib (compatibility version 0.0.0, current version 0.0.0)
  libax.dylib (compatibility version 0.0.0, current version 0.0.0)
  libsqlite3.dylib (compatibility version 0.0.0, current version 0.0.0)
  libfreetype.dylib (compatibility version 0.0.0, current version 0.0.0)
  /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
  /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 19.0.0)
  /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
  /System/Library/Frameworks/ForceFeedback.framework/Versions/A/ForceFeedback (compatibility version 1.0.0, current version 1.0.2)
  /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 155.0.0)
  /System/Library/Frameworks/CoreAudio.framework/Versions/A/CoreAudio (compatibility version 1.0.0, current version 1.0.0)
  /System/Library/Frameworks/AudioUnit.framework/Versions/A/AudioUnit (compatibility version 1.0.0, current version 1.0.0)

and this is on libn, zlib and png:

libn.dylib:
  libn.dylib (compatibility version 0.0.0, current version 0.0.0)
  /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)

libpng.dylib:
  libpng.dylib (compatibility version 0.0.0, current version 0.0.0)
  libzlib.dylib (compatibility version 0.0.0, current version 0.0.0)
  /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)

libzlib.dylib:
  libzlib.dylib (compatibility version 0.0.0, current version 0.0.0)
  /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)

Now I use dlopen() to open all the dynamic libraries in my ‘lib’ dir, in order, using:

/** Open a dynamic library file */
void *Type__(open) (char *path) {
  void *impl = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
  if (impl == NULL) {
    char *err = dlerror();
    N_LOG(N_LOG_DEBUG, "Failed to open: %s", err);
  }
  else {
    N_LOG(N_LOG_DEBUG, "Happy open: %s", path);
    rtn = nPosixLinker__Lib(path, impl);
  }
  return rtn;
}

…and get errors/messages like this:

Happy open: /Users/doug/projects/libni/build/tests/IImageLoader/lib/libzlib.dylib
Happy open: /Users/doug/projects/libni/build/tests/IImageLoader/lib/libstb.dylib
Happy open: /Users/doug/projects/libni/build/tests/IImageLoader/lib/libsqlite3.dylib
Happy open: /Users/doug/projects/libni/build/tests/IImageLoader/lib/libSDL2.dylib
Happy open: /Users/doug/projects/libni/build/tests/IImageLoader/lib/libn.dylib
Failed to open: dlopen(/Users/doug/projects/libni/build/tests/IImageLoader/lib/libpng.dylib, 10): Library not loaded: libzlib.dylib
  Referenced from: /Users/doug/projects/libni/build/tests/IImageLoader/lib/libpng.dylib
  Reason: image not found
Failed to open: dlopen(/Users/doug/projects/libni/build/tests/IImageLoader/lib/libni.dylib, 10): Library not loaded: libn.dylib
  Referenced from: /Users/doug/projects/libni/build/tests/IImageLoader/lib/libni.dylib
  Reason: image not found
Happy open: /Users/doug/projects/libni/build/tests/IImageLoader/lib/liblua.dylib
Happy open: /Users/doug/projects/libni/build/tests/IImageLoader/lib/libfreetype.dylib
Happy open: /Users/doug/projects/libni/build/tests/IImageLoader/lib/libax.dylib
Failed to open: dlopen(/Users/doug/projects/libni/build/tests/IImageLoader/lib/libtest-ni-IImageLoader__.dylib, 10): Library not loaded: libni.dylib
  Referenced from: /Users/doug/projects/libni/build/tests/IImageLoader/lib/libtest-ni-IImageLoader__.dylib
  Reason: image not found

So there’s definitely something weird going on here. zlib is opened before libpng, but libpng can’t resolve the reference. libn is opened before libni, but libni can’t resolve the reference.

It’s like my RTLD_GLOBAL is being ignored by dlopen(), or the dependency (eg. libn) isn’t finding the loaded library (blah/libn.dylib) because the paths are different…

In fact, I cant seem to make dlopen() open a library which has a dependency at all so I figure I must be doing something wrong.

Any suggestions?

On BSD and linux this all just works; it’s definitely an issue strictly related to the way OSX is handling these libraries.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T00:56:41+00:00Added an answer on June 15, 2026 at 12:56 am

    Looks like this is a duplicate of this, but I totally didn’t find it until after I already figured out the solution, so I’m going to leave both the question and this link here for now.

    Sort answer: Build the library using -install_name @rpath/lib

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a library made in C++/GDI that I am trying to port to
I have a library that draw on to given HDC using GDI+ apis. I
I have document library where I am using the Out-Of-the box document approval workflow.
I am using VS 2008. I have Library 5 Lib file A.lib B.lib C.lib
I need to have library that can be used as memcache with my codeigniter.
I have a standalone (3rd party) app that I'm trying to launch using a
I have a library I am trying to use with a Dot Net 4
I have a library with an Interface. Public Interface Progress { int ProgressValue{get;set;}, string
I have a library project that should be the base for several web applications.
We have a library created as both .lib and .dll (it's a big library

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.