dlopen() error image not found

為{幸葍}努か 提交于 2019-12-19 18:11:28

问题


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.


回答1:


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.




回答2:


use:

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

then check it with:

otool -D mylib.dylib


来源:https://stackoverflow.com/questions/6711908/dlopen-error-image-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!