Dylib error 'Library not loaded' distributing application - opencv

I'm developing an app in objective-C++ that uses dynamic libraries of OpenCV and VTK but I've a problem on distribution, if I launch my app in a different system I got this issue:
Dyld Error Message:
Library not loaded: #executable_path/../Frameworks/libvtkCommon.5.6.1.dylib
Referenced from: /myApp.app/Contents/MacOS/myApp
Reason: no suitable image found. Did find:
/myApp.app/Contents/MacOS/../Frameworks/libvtkCommon.5.6.1.dylib: open() failed with errno=13
/myApp.app/Contents/MacOS/../Frameworks/libvtkCommon.5.6.1.dylib: open() failed with errno=13
I've rebuilt my dylibs with install_name_tool to point to: #executable_path/../Frameworks and in "build phase" of myApp's target I've added "copy files" phase with destination "Frameworks" for my dylibs. Where is the problem?

Check your application bundle and make sure the file that got copied into Frameworks is the actual dylib and not a symbolic link file. Also, did you run install_name_tool on both the dylib file and your executable? Look at this page under Shared Libraries for an example.
Also see this question.

Related

dyld: Library not loaded: #rpath/X.framework/X

When I try to run app on real device,I face this issue.I tried these solutions but they don't work
I cleaned derived data and delete the app
I changed frameworks, libraries , embedded content to "embed & sign"
Rechecking if X.XCFramework is in "Link binaries with libraries " at Build Phase or
not.but it was there
Copy framework in copy bundle resources
I changed installation directory to #executable_path/Frameworks in framework build setting
I set Framework search paths and Library search path to physical framework path in host application
The Xcode version is 13.0
dyld: Library not loaded: #rpath/X.framework/X
Referenced from: /var/containers/Bundle/Application/D3E0B89E-B0B2-4511-9B33-84EA9AF51821/Y.app/Y
Reason: no suitable image found. Did find:
/private/var/containers/Bundle/Application/D3E0B89E-B0B2-4511-9B33-84EA9AF51821/Y.app/Frameworks/X.framework/X: missing LC_DYLD_INFO load command

Used dylib in my IOS framework getting error after App lauch

I have an embedded dylib in my IOS framework and trying use this framework in my application after launch is giving me an error.
Error:
dyld: Library not loaded:*.dylib
Referenced from: /private/var/containers/Bundle/Application/43345D9E-F58D-4FBD-9C22-DD2554AE0484/COCO.app/Frameworks/*.framework/cocosdk
Reason: image not found
.dylib is embedded in "Framework" folder in my IOS framework.
things I've tried:
install_name_tool -change oldpath newpath libname
The framework already present in Embedded Binarie
Present in Build Phases Copy Files to Framework
Added Runpath search path as "#rpath/*.dylib", "#executable_path/Frameworks", "#executable_path/Frameworks/*.framework/Frameworks/*.dylib", "#rpath/Frameworks/*.framework/Frameworks/*.dylib"
Added same path in Dynamic Lib install name
Deleted all Derived Data
Clean the project and tried
8.'Build Libraries for Distribution' == true.
Ran into this issue recently, when switching from Fat/Universal binary to creating a XCFramework.
Check in your framework project if 'Build Libraries for Distribution' == true.

Using CMake to copy .frameworks to iOS app bundle

A library I'm using recently switched to distribution as a .framework.
In my existing CMake file, I've been successful at getting it to link with my iOS app, but am getting:
dyld: Library not loaded: #rpath/Pizza.framework/Pizza
Referenced from: /var/mobile/Containers/Bundle/Application/D71ED298-C287-4B2F-8AFA-710A14C06D75/pizzashop.app/pizza
Reason: image not found
when I install it from Xcode. If I manually add it to my xcode project, in the "embedded binaries" section then I'm good (see image below)
So I've concluded that the problem is getting the .framework into my app bundle. I've come across this question and looked at the linked QT example, but I'm still trying to orient myself here as I'm finding the syntax a bit opaque.
Is CMake's BundleUtilities what I want to use here? In looking at the BundleUtilities example I'm a bit lost:
set(APPS ...) # paths to executables
set(DIRS ...) # directories to search for prerequisites
INSTALL(CODE "
include(BundleUtilities)
fixup_bundle(\"${APPS}\" \"\" \"${DIRS}\")
" COMPONENT Runtime)
Is this OSX-specific or can I apply it similarly to iOS?
We didn't end up finding an ideal solution, and ended up doing things a bit more manually than preferred:
We added a custom command we run after the build is complete, but before it is packaged (see CMake's add_custom_command).
The custom command does the following:
creates a Frameworks directory under our app bundle folder (make sure it's somewhere where it will get copied in your packaging process).
we use cp -aH to copy all frameworks into this Frameworks directory
we then re-sign each framework in this directory using:
codesign --force --verbose Computers.framework --sign "$2"
Add the Frameworks directory to your search paths:
set_target_properties(${EXE_NAME} PROPERTIES
XCODE_ATTRIBUTE_LD_RUNPATH_SEARCH_PATHS "#executable_path/Frameworks")

How to attach library to ios project?

I'm developing a command line tool app that uses AppList library. But when i trying to run in on my device, the error occured:
dyld: Library not loaded: /usr/lib/libapplist.dylib
Referenced from: /usr/bin/testApp
Reason: image not found
Is it possible to attach libapplist.dylib to project package?
All dylibs have an installation path inside mach-o header. That path is placed in your application import section so that linker could find the dylib. When your process is launched dyld searches that path for the dylib.
You can check that path like this:
otool -D libapplist.dylib
That's what dyld is telling you - it couldn't find the dylib. You have two options:
Place your dylib where it needs to be
Change installation path.
If it's your dylib you can change it inside xcode project settings of your dylib - search for installation directory. When you rebuild dylib and application linking it they will contain the new path.
If you can't recompile the dylib then you need to change it manually. Here is how you can do it:
install_name_tool -id #executable_path/libapplist.dylib libapplist.dylib
#executable_path tells the linker to search for dylib where application executable is located.
Its simple go to build phases and link framework and library
go to build phases in app settings
add the library which you want

"directory not found for option" Flurry Analytics Library

Whenever I reopen my XCode project, I always get these errors cause by the flurry analytics library:
ld: warning: directory not found for option '-L/Users/...'
ld: warning: directory not found for option '-LFiles/Flurry'
ld: library not found for -lFlurry_5.0.0
clang: error: linker command failed with exit code 1 (use -v to see invocation)
At first, when the project is opened, it will not build, then if I drag the flurry library to frameworks (even though it is already visibly there), it will build, but there will still be the two warnings.
If I delete the library search paths, then the error and warnings go away, but when I reopen the project, they always come back.
Is there anyway to fix this so the warnings are not always there and I don't have to re-add the library every time I open the project?
There is a reference issue with the library.
Remove existing references in the library search paths.
Remove the Library if present inside the Project folder.
Copy the Library inside the project folder say "Flurry".
Reference the library as a relative path (not absolute) in library search path as "$(SRCROOT)/Flurry"

Resources