I build a static library that links against other frameworks, particularly CoreLocation. I want to use features provided by iOS 5 but be compatible with 4.3.
My app crash at launch when I start it on iOS devices in 4.3 with this error :
Date/Time: 2012-08-22 16:44:53.900 +0200
OS Version: iPhone OS 4.3.3 (8J3)
Report Version: 104
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x00000001, 0xe7ffdefe
Crashed Thread: 0
Dyld Error Message:
Symbol not found: _UIKeyboardDidChangeFrameNotification
The problem I encounter is described in this post : iOS 4 app crashes at startup on iOS 3.1.3: Symbol not found: __NSConcreteStackBlock.
But how do you deal with that when building a static library ?? I can't compile when I set the -weak-lSystem flag. Here is a trace :
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: -dynamic not specified, -all_load invalid
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: -dynamic not specified the following flags are invalid: -ObjC
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: can't locate file for: -weak-lSystem
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: -weak-lSystem is not an object file (not allowed in a library)
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/usr/lib/libxml2.2.dylib is a dynamic library, not added to the static library
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/usr/lib/libxml2.2.dylib is a dynamic library, not added to the static library
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/usr/lib/libz.dylib is a dynamic library, not added to the static library
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/usr/lib/libz.dylib is a dynamic library, not added to the static library
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool failed with exit code 1
Resolved
See accepted answer below and do not forget to mark libraries used in different versions as Optional in Xcode. Ex: I use UIKit new notification for iOS 5 but my deployement target is 4.3 so I need to mark this library as Optional in order to make things work. It is the same for CoreLocation CLGeocoder new iOS 5 class.
The problem is that UIKeyboardDidChangeFrameNotification is not available on iOS 4 and therefore the dynamic loader (Dyld) fails.
From the perspective of the static library developer you don't have to do anything. The -weak-lSystem flag should be set in the Xcode project that uses the static library for an application (see the post mentioned in the question) - not in the project for the static library.
Related
I'm trying to build a JVM application (mostly Kotlin) on my M1 MacBook that uses CouchbaseLite.
I have this in my build.gradle file:
implementation "com.couchbase.lite:couchbase-lite-java:3.0.0-beta02"
(also tried it with a non-beta version 2.8.4)
Gradle sync + build is fine but everytime I run the up and try to create a database
db = Database(LOCAL_DB_NAME, config)
I get the following error:
java.lang.IllegalStateException: Cannot load native library libLiteCore.dylib #/Users/ale/Projects/server/CouchbaseLiteTemp/5e3b1711cace9de693b3e1e0bea0f2f8/libLiteCore.dylib for Mac OS X/aarch64
at com.couchbase.lite.internal.NativeLibrary.load(NativeLibrary.java:113)
at com.couchbase.lite.internal.CouchbaseLiteInternal.init(CouchbaseLiteInternal.java:80)
at com.couchbase.lite.CouchbaseLite.init(CouchbaseLite.java:54)
at com.couchbase.lite.CouchbaseLite.init(CouchbaseLite.java:42)
at com.couchbase.lite.CouchbaseLite.init(CouchbaseLite.java:33)
at de.ihaus.Main.Database.CouchbaseManager.initContext(CouchbaseManager.kt:34)
at de.ihaus.Main.Dingo$main$1.invoke(Dingo.kt:15)
at de.ihaus.Main.Dingo$main$1.invoke(Dingo.kt:14)
at de.ihaus.Main.Login.LoginManager.onLoginSuccess(LoginManager.kt:64)
at de.ihaus.Main.Login.LoginManager$LoginWorker.run(LoginManager.kt:53)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.UnsatisfiedLinkError: /Users/ale/Projects/server/CouchbaseLiteTemp/5e3b1711cace9de693b3e1e0bea0f2f8/libLiteCore.dylib: dlopen(/Users/ale/Projects/server/CouchbaseLiteTemp/5e3b1711cace9de693b3e1e0bea0f2f8/libLiteCore.dylib, 0x0001): tried: '/Users/ale/Projects/server/CouchbaseLiteTemp/5e3b1711cace9de693b3e1e0bea0f2f8/libLiteCore.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/lib/libLiteCore.dylib' (no such file)
at java.base/java.lang.ClassLoader$NativeLibrary.load0(Native Method)
at java.base/java.lang.ClassLoader$NativeLibrary.load(ClassLoader.java:2442)
at java.base/java.lang.ClassLoader$NativeLibrary.loadLibrary(ClassLoader.java:2498)
at java.base/java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2694)
I've looked around but CouchbaseLite is supposed to work on an M1.
What am I doing wrong?
Turns out the problem was the Apple Silicon version of the JDK.
If I run the project with an x86_64 version of the JDK, Rosetta kicks in and it works. Will have to live with the performance hit for now, but at least I'm not blocked anymore.
Unfortunately, CBL-Java doesn't support Native Mac M1 yet.
I am trying to rebuild my xamarin.iOS project in release mode and i am getting following Errors:
linker command failed with exit code 1 (use -v to see invocation).
error MT5209: Error: warning: ignoring file /Users/admin/Desktop/1DMAPP/MobileApp/MobileApp/MobileApp.iOS/obj/iPhone/Release/mtouch-cache/BEMCheckBox.framework/BEMCheckBox, missing required architecture armv7s in file /Users/admin/Desktop/1DMAPP/MobileApp/MobileApp/MobileApp.iOS/obj/iPhone/Release/mtouch-cache/BEMCheckBox.framework/BEMCheckBox (4 slices) (MobileApp.iOS) Native linking
/Users/admin/Desktop/1DMAPP/MobileApp/MobileApp/MobileApp.iOS/MTOUCH: Error MT5211: Native linking failed, undefined Objective-C class: BEMCheckBox. The symbol '_OBJC_CLASS_$_BEMCheckBox' could not be found in any of the libraries or frameworks linked with your application. (MT5211) (MobileApp.iOS)
/Users/admin/Desktop/1DMAPP/MobileApp/MobileApp/MobileApp.iOS/MTOUCH: Error MT5211: Native linking failed, undefined Objective-C class: BEMCheckBoxGroup. The symbol '_OBJC_CLASS_$_BEMCheckBoxGroup' could not be found in any of the libraries or frameworks linked with your application. (MT5211) (MobileApp.iOS)
/Users/admin/Desktop/1DMAPP/MobileApp/MobileApp/MobileApp.iOS/MTOUCH: Error MT5202: Native linking failed. Please review the build log. (MT5202) (MobileApp.iOS)
I am using the latest and stable version of packages.
My Link Behavior is "Don't Link"
My project supports all architectures
I want to build and release my iOS app. Native linking error is not allowing me to do this.
I am trying to create a xamarin.ios binding library using the brother printer mobile sdk for ios (BRPtouchPrinterKit.framework).
The Xamarin.iOS binding project compiles and builds without errors, when you use the "BRPtouchPrinterKit" which is under "/Users/[username]/Desktop/BrotherPrinterSDK/bpsdkBinding/bpsdkBinding/BRPtouchPrinterKit.framework/Versions/A/" in mac.
When I try to use the dll in a sample and when try to run the same I am getting the following errors during runtime.
clang : error : linker command failed with exit code 1 (use -v to see invocation)
MTOUCH : error MT5210: Native linking failed, undefined symbol: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::find(char, unsigned long) const. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
MTOUCH : error MT5210: Native linking failed, undefined symbol: std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::compare(unsigned long, unsigned long, char const*, unsigned long) const. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
MTOUCH : error MT5210: Native linking failed, undefined symbol: std::__1::__shared_weak_count::__get_deleter(std::type_info const&) const. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
MTOUCH : error MT5210: Native linking failed, undefined symbol: std::__1::__vector_base_common<true>::__throw_length_error() const. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
MTOUCH : error MT5210: Native linking failed, undefined symbol: std::__1::__basic_string_common<true>::__throw_length_error() const. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
I believe your issue is the same as this one on SO:
Linking failure with a MonoTouch native library binding
In which case you need to add a reference to libc++ (-lc++) and make sure that you set the IsCxx flag to true. This can be done in your linkwith.cs file in your binding project as in the post above, e.g.:
[assembly: LinkWith (... LinkerFlags = "-lc++ [and you may have some other -l* libs listed here here already]", IsCxx = true)]
If you do not have a linkwith.cs file, then you should be able to add the above reference to -lc++ and set the IsCxx flag to true in the properties for the framework. (Right click the framework and choose Properties)
Thanks #jgoldberger
For anyone who might be coming across same set of issues, Please go through the link https://forums.xamarin.com/discussion/comment/340581
I can successfully run my app in IOS 8 but in IOS 7, my app crashes.
The message is:
dyld: Library not loaded: /System/Library/Frameworks/LocalAuthentication.framework/LocalAuthentication
Referenced from: /Users/burakkilic/Library/Developer/CoreSimulator/Devices/A0210158-BC6C-43AA-9D85-AA8DE6115AAA/data/Applications/xxx
Reason: no suitable image found. Did find:
/System/Library/Frameworks/LocalAuthentication.framework/LocalAuthentication: mach-o, but wrong architecture
How can I solve it?
You could weak link LocalAuthentication.framework and conditionally access the LocalAuthentication API at runtime.
The latter can be done by either:
Checking the iOS version you are running.
Using reflection to test for the presence of API methods (respondsToSelector, et al).
I have an application that uses a few classes found only in 10.7 Lion. (For example, NSFileCoordinator.)
When my application launches, it can use NSFileCoordinator to coordinate read access to the data store. (I save to XML.)
The application launches fine under 10.7 Lion, but when launching under 10.6 Snow Leopard, the application crashes with the error shown below.
My base SDK is set to 10.7, and the deployment target is 10.6. As far as I can tell, all my code is properly wrapped, like:
if (NSClassFromString(#"NSFileCoordinator") != nil) {
// Do something the 10.7 way
} else {
// Do something the 10.6 way
}
But for some reason, I'm still seeing the crash. Since the Base SDK is 10.7, I can't run the application under Xcode in 10.6, making debugging difficult. Additional messages are being logged to the console:
9/1/11 9:48:03 AM [0x0-0x18018].com.me.myapp[173] dyld: Symbol not found: _OBJC_CLASS_$_NSFileCoordinator
9/1/11 9:48:03 AM [0x0-0x18018].com.me.myapp[173] Referenced from: /Volumes/Macintosh HD/Users/Me/Library/Developer/Xcode/DerivedData/Mac-ebdxgdvcqfnptlftkreamrwdxetd/Build/Products/Debug/myapp.app/Contents/MacOS/myapp
9/1/11 9:48:03 AM [0x0-0x18018].com.me.myapp[173] Expected in: /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation
9/1/11 9:48:03 AM [0x0-0x18018].com.me.myapp[173] in /Volumes/Macintosh HD/Users/Me/Library/Developer/Xcode/DerivedData/Mac-ebdxgdvcqfnptlftkreamrwdxetd/Build/Products/Debug/myapp.app/Contents/MacOS/myapp
And the crash report:
Process: myapp [137]
Path: /Volumes/Macintosh HD/Users/Me/Library/Developer/Xcode/DerivedData/Mac-ebdxgdvcqfnptlftkreamrwdxetd/Build/Products/Debug/myapp.app/Contents/MacOS/myapp
Identifier: com.me.myapp
Version: 1.5.0 (150)
Code Type: X86-64 (Native)
Parent Process: launchd [92]
Date/Time: 2011-09-01 09:40:32.591 -0400
OS Version: Mac OS X 10.6.8 (10K549)
Report Version: 6
Interval Since Last Report: 2009 sec
Crashes Since Last Report: 5
Per-App Crashes Since Last Report: 5
Anonymous UUID: 32784C79-0821-471E-BCBF-BE5874774075
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000002, 0x0000000000000000
Crashed Thread: 0
Dyld Error Message:
Symbol not found: _OBJC_CLASS_$_NSFileCoordinator
Referenced from: /Volumes/Macintosh HD/Users/Me/Library/Developer/Xcode/DerivedData/Mac-ebdxgdvcqfnptlftkreamrwdxetd/Build/Products/Debug/myapp.app/Contents/MacOS/myapp
Expected in: /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation
in /Volumes/Macintosh HD/Users/Me/Library/Developer/Xcode/DerivedData/Mac-ebdxgdvcqfnptlftkreamrwdxetd/Build/Products/Debug/myapp.app/Contents/MacOS/myapp
#Anomie has the right answer but let me expand on it some more.
Here is the code of a command line tool that is similar to what you are doing:
int main (int argc, const char * argv[])
{
#autoreleasepool {
if (NSClassFromString(#"NSFileCoordinator")) {
NSLog(#"Version >= 10.7");
} else {
NSLog(#"Version < 10.7");
}
}
return 0;
}
The only framework that this program links to is Foundation. But in order to weakly link to this framework you must do the following:
Click on the project in the project browser
Go to "Build Phases"
Go to "Link Binary With Libraries" and remove "Foundation.framework"
Go to "Build Settings" and add the following "Other Linker Flags":
-weak_framework Foundation
Rebuild your project. I've tested on OS X 10.6 and 10.7 and neither crashed and both produced the expected output. Hope this helps.
You need to weakly link the framework, so these unresolved symbols won't be an error at load time.