Michael Wildermuth
Michael Wildermuth

Reputation: 5852

dlopen() error image not found

I have software that first loads a .dylib lets call libFirst.dylib using the following command:

void* handle = dlopen(path.c_str(), RTLD_LAZY | RTLD_GLOBAL);

Later on inside a function from the loaded libFirst.dylib I attempt to load another .dylib using the same command but for libSecond.dylib, the loading of this shared library gives me the following warnings in my Xcode console:

error warning: Ignored unknown object module at 0x129310 with type 0x8a8399

dlerror: dlopen(/path/libSecond.dylib, 9): Library not loaded: libFirst.dylib
  Referenced from: /path/libSecond.dylib
  Reason: image not found

What I don't get is that its says libFirst.dylib is not loaded but I am currently inside a function from libFirst.dylib, so how can this be?

All my paths in DYLD_LIBRARY_PATH appear correct too.

Thanks in advance, I have been stuck on this for days.

Upvotes: 8

Views: 13703

Answers (3)

user4540741
user4540741

Reputation: 352

I think an easier way to get around this error would be to revert to an earlier version where you were not getting this error. Right click on the project folder and navigate to local history to revert to an earlier version. I verified this to be working on the android studio installed on Mac OS Big sur.

Upvotes: 1

user1390106
user1390106

Reputation: 23

use:

install_name_tool -id @executable_path/../Frameworks/mylib.dylib mylib.dylib

then check it with:

otool -D mylib.dylib

Upvotes: 1

Michael Wildermuth
Michael Wildermuth

Reputation: 5852

I ended up using -install_name to change the install name of all my libraries to @rpath/dylibName.dylib and then in Xcode I set the Runpath Search paths using @loader_path to find all my .dylibs that I was using.

Upvotes: 4

Related Questions