dlopen() error image not found
Asked Answered
A

3

8

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.

Antiquated answered 15/7, 2011 at 18:58 Comment(6)
Have you tried something like strace? It might give you a more information to see specifically which call is failing.Payroll
My stack trace shows the function which is calling dlopen called CreateModule on the libSecond.dylib, which is a function inside libFirst.dylib.Antiquated
Not the stack trace - strace stands for system trace. It's traces function calls like opening files, stat'ing inodes, etc. It might shed some light on where exactly your OS is looking.Payroll
I had to use dtruss since I am on a OSX, but here is what happens after the open on libSecond.dylib happens: stat64("libFirst.dylib\0", 0xBFFFE0FC, 0x1)= -1 Err#2 stat64("/Users/mwildermuth/lib/libFirst.dylib\0", 0xBFFFE4DC, 0x1) = -1 Err#2 tat64("/usr/local/lib/libFirst.dylib\0", 0xBFFFE4DC, 0x1) = -1 Err#2 stat64("/usr/lib/libFirst.dylib\0", 0xBFFFE4EC, 0x1)= -1 Err#2 Then after that I get my usual error from the question above. None of the locations are correct in the stat64 calls, could this by the reason for the problem? If so how do I fix it. Again thanks for your time.Antiquated
Sure - I know firsthand how frustrating it can be :) Yeah, it looks like it is simply looking in the wrong place. I don't know enough about OSX to help you with that, but perhaps there is a library search path you can fix?Payroll
Thanks for all your time, I feel like you got me going in the right the direcitonAntiquated
A
4

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.

Antiquated answered 22/7, 2011 at 16:32 Comment(1)
Hi @MartinDelille. I did this over 3 years ago so I don't have the exact command line, but here is a blog about how to use it: log.zyxar.com/blog/2012/03/10/install-name-on-os-xAntiquated
D
1

use:

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

then check it with:

otool -D mylib.dylib
Depoliti answered 20/5, 2018 at 23:7 Comment(0)
R
1

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.

Rollin answered 3/2, 2021 at 12:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.