Binding brother printer SDK framework to xamarin ios binding library - objective-c

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

Related

Native linking failed. Please review the build log in Xamarin.iOS Cross platform

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.

How to solve "Library not loaded" error because of LocalAuthentication.framework?

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).

Undefined symbols for architecture armv7 when using ZXing library in XCode 5.1

i need to scan QR Code for that i have used Zxing 3rd party library but i got following error :
"undefined symbol for architecture armv7"in libZxingWidget.a
Undefined symbols for architecture i386:
"std::string::c_str() const", referenced from:
zxing::qrcode::Detector::computeDimension(zxing::Ref<zxing::ResultPoint>, zxing::Ref<zxing::ResultPoint>, zxing::Ref<zxing::ResultPoint>, float) in libZXingWidget.a(Detector-B8B28E953F840D47.o)
zxing::GridSampler::checkAndNudgePoints(zxing::Ref<zxing::BitMatrix>, std::vector<float, std::allocator<float> >&) in libZXingWidget.a(GridSampler.o)
zxing::qrcode::DecodedBitStreamParser::append(std::string&, std::string const&, char const*) in libZXingWidget.a(DecodedBitStreamParser-64E27B33E79CBC52.o)
i have done all setting which is explained in this link here .
Project Descriptions :
IOS-SDK : 7.1
X-code : 5.1
Mac OS " 10.9
Zxing version : 2.0
Please Reply me as soon as possible ,
your help is appreciated
Thanks

Static Library and -weak-lSystem

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.

LNK2001: What have I forgotton to set?

Following on from my previous question regarding debugging of native code, I decided to create a simple test from a console app as I wasn't getting anywhere with debugging the service directly.
So I created a vc6 console app, added the dll project to the workspace and ran it.
Instead of executing as expected it spat out the following linker errors:
main.obj : error LNK2001: unresolved external symbol "int __stdcall hmDocumentLAdd(char *,char *,long,char *,char *,long,long,long,long *)" (?hmDocumentLAdd##YGHPAD0J00JJJPAJ#Z)
main.obj : error LNK2001: unresolved external symbol "int __stdcall hmGetDocBasePath(char *,long)" (?hmGetDocBasePath##YGHPADJ#Z)
Debug/HazManTest.exe : fatal error LNK1120: 2 unresolved externals
This seems to be a simple case of forgetting something in the linker options: However everything seems to be normal, and the lib file, dll and source is available. If I change the lib file to load to nonsense it kicks up the fatal error LNK1104: cannot open file "asdf.lib", so that isn't a problem.
I have previously linked to dll and they have just worked, so what I have forgotton to do?
Update: As per this thread I looked to see if I could find out any additional information. This is what dumpbin from VS2005 gives me.
> dumpbin /linkermember Hazardman.lib | findstr "DocumentLAdd"
F6DC __imp__hmDocumentLAdd#36
F6DC _hmDocumentLAdd#36
5B __imp__hmDocumentLAdd#36
5B _hmDocumentLAdd#36
Then running it through undname results in:
> undname ?_hmDocumentLAdd#36
Microsoft (R) C++ Name Undecorator
Copyright (C) Microsoft Corporation. All rights reserved.
Undecoration of :- "?_hmDocumentLAdd#36"
is :- "?_hmDocumentLAdd#36"
Which is wrong. If I put in the mangled name from the IDE it gives the lot better result of:
> undname ?hmDocumentLAdd##YGHPAD0J00JJJPAJ#Z
Microsoft (R) C++ Name Undecorator
Copyright (C) Microsoft Corporation. All rights reserved.
Undecoration of :- "?hmDocumentLAdd##YGHPAD0J00JJJPAJ#Z"
is :- "int __stdcall hmDocumentLAdd(char *,char *,long,char *,char *,long,long,l
ong,long *)"
Now I have this information, what can I do with it? It seems from this Raymond Chen article I can manually fix it but tweaking an option, but my I can't discern from my results what option is needed (is there an 'ignore all parameters' checkbox?!).
So it seems that it is looking for non-existant functions or the parameters of the function have been left off (or dumpbin doesn't like VC6 libs), but it stil doesn't get me nearer my goal of fixing my problem.
Are you using the correct calling convention?
Your library appears to use stdcall. Maybe your test code is using cdecl (appears to be the default).
According to this page, the linker name decorations differ between the caling conventions so this can explain the symptoms you are seeing.