How to attach library to ios project? - ios

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

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.

"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"

XCode linking error to cached library information without being called (Undefined symbols for architecture)

I am attempting to use a static library (.a) for which I also have the header files (no .m files), but when I add the library to my target (without even referencing/importing the library in my project code), I receive the Undefined symbols for architecture armv7 linking error at compile time. The linker is complaining about classes that supposedly no longer exist in the newest version of the library, and may be using cached data? That suspicion could be supported by the finding that if I create a blank project and add the library in the exact same way as I added it to my project, the new project compiles without issue. But on another note, when I grep my file system for the classes/ivars the linker is complaining about, I get matches in my static library file and my xcuserdata workspace folders. So I am wondering if the issue is in my project, the library I am trying to import, or the way in which I am trying to add the library to my project? And also, why do I get linker errors when I am not even importing/calling the library from my code? I am using XCode 4.6.1.
The linking error is as follows:
Undefined symbols for architecture armv7:
"_OBJC_IVAR_$_GenericPopupView.delegateTheme", referenced from:
-[MyListView setDelegateTheme:] in myLib.a(MyListView.o)
-[MyListView tableView:cellForRowAtIndexPath:] in myLib.a(MyListView.o)
"_OBJC_CLASS_$_SampleMarkView", referenced from:
objc-class-ref in myLib.a(MyListView.o)
"_OBJC_CLASS_$_CheckMarkView", referenced from:
objc-class-ref in myLib.a(MyListView.o)
"_OBJC_METACLASS_$_GenericPopupView", referenced from:
_OBJC_METACLASS_$_MyListView in myLib.a(MyListView.o)
"_OBJC_CLASS_$_GenericPopupView", referenced from:
_OBJC_CLASS_$_MyListView in myLib.a(MyListView.o)
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I added the library to my target by performing the following steps:
Right-click on my project
Select 'Add Files to "My Project"'
Locate the .a file through the popup Finder window
Verify the library path is in my Target -> Build Settings -> Library Search Paths (automatically added when I complete step 3)
Add the header directory to Target -> Build Settings -> Header Search Paths
Verify that the library is listed in Target -> Build Phases -> Link Binary With Libraries
Verify that the library is compiled for armv7 via file, otool, & lipo (I heard the library may also include armv6s, but I didn't see armv6 when I used the three commands)
$ file myLib.a
myLib.a: Mach-O universal binary with 2 architectures
myLib.a (for architecture armv7): current ar archive random library
myLib.a (for architecture cputype (12) cpusubtype (11)): current ar archive random library
$ otool -L myLib.a
Archive : myLib.a (architecture cputype (12) cpusubtype (11))
…
$ lipo -info myLib.a
Architectures in the fat file: myLib.a are: armv7 (cputype (12) cpusubtype (11))
Here are things I have tried inbetween each compile attempt without any success:
Clean the project with (apple)+shift+k
Clean the build directory (DerivedData) with (apple)+alt+shift+k
Delete all the DerivedData directories from the command line
Remove and re-add the library and its headers to my project
Add the library without the headers
Put the libraries in a project that is a target dependency instead of in my project directly
Note that I am unable to add the library as a Target Dependency in Build Settings; should I be able to?
I am also unable to add the library to the target's Build Scheme (via XCode menu's Product -> Scheme -> Edit Scheme... -> Build -> +)
Check the minimum iOS version via iOS Deployment Target in Build Settings – both my target and the library are iOS 6.0
Removed all target search paths except those required for my project to build without the new library as shown below (most importantly I removed the DerivedData from the linker path); my overall project build settings (not the target's build settings) contains no other search paths
Header Search Paths
$(BUILT_PRODUCTS_DIR)/usr/local/include
$(SRCROOT)/../MyLibDirectory/headers
Library Search Paths
$(inherited)
$(SRCROOT)/../TargetDependencyDirectory
$(SRCROOT)/../openssl/lib
$(SRCROOT)/../MyLibDirectory
Removed all other instances of the library on my machine (old versions)
Set the user-defined build setting USE_HEADERMAP = NO
Install on a newly imaged machine with a fresh project checkout and repeat all of the above steps
Add –ObjC++ to the other linker flags (-ObjC is already a linker flag)
Use armv6s by itself and with armv6 in the Valid Architecture under Build Settings for my target and the target dependencies
Set Build Active Architecture Only to Yes
Switched between adding the library in a project group vs. at the parent project group level
Add an import and instantiation of an object from the library in my project code
Played with the library's different settings for Location under Identity and Type in the Utilities window on the right side of XCode when the library is selected
Add the library to the target's Build Phases -> Link Binary With Libraries via the + then Add Other...
I have already tried the recommended steps in these and other posts (only the last two of these listed have actual instructions):
Xcode referencing old
framework
Xcode referencing old/removed frameworks, causing multiple interface
declarations
Xcode custom framework - No known method error
Undefined symbols for architecture armv7
I have not tried changing all of my files to .mm (I didn't need to for previous versions of this library), but I have a lot of .m files that I think might break if I change them all...
Any help or succestions are greatly appreciated! I'm really having a hard time figuring out why this new version of the library is giving me problems.
I resolved my own problem, or rather, the issue was with the black box of a library that I was including. From the command line performed the following command in a terminal window:
grep SampleMarkView myLib.a
Which resulted in:
Binary File:myLib.a matches
I talked to the person who created the library and they sent me an updated version that didn't cause the problem - I guess they had old references in their code. So at the very least I hope this post provides a list of various things to try if you are having a library referencing problem!

Dylib error 'Library not loaded' distributing application

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.

Resources