user3124624
user3124624

Reputation: 1216

Binding Native iOS Library with xamarin

I am able to create a proper dll for .a library

My LinkWith file

    [assembly: LinkWith ("libSwiperAPI.a", IsCxx = true, 
    LinkTarget = LinkTarget.Simulator | LinkTarget.ArmV7 | LinkTarget.ArmV7s, 
    ForceLoad = true, Frameworks = "CoreAudio AudioToolbox AVFoundation MediaPlayer", 
    LinkerFlags = "-ObjC -lc++" )]

In this tried using Links flags -lstdc++ -lz also but did not work.

I even tried adding -cxx in Addition mtouch Argjuments and -gcc_flags.

When I am trying to use the dll file in my demo project. I am getting error

Compiling to native code
/Developer/MonoTouch/usr/bin/mtouch -sdkroot "/Applications/Xcode.app/Contents/Developer" --cache "/Users/sathish/Projects/Xamarin/RoamPayAPITest/RoamPayAPITest/obj/iPhone/Debug/mtouch-cache" --nomanifest --nosign -dev "/Users/sathish/Projects/Xamarin/RoamPayAPITest/RoamPayAPITest/bin/iPhone/Debug/RoamPayAPITest.app" -r "/Developer/MonoTouch/usr/lib/mono/2.1/System.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/System.Xml.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll" -r "/Users/sathish/Projects/Xamarin/RoamPayAPITest/References/SwipeAPIBinding.dll" -debug -sdk "7.0" -targetver "7.0" --abi=armv7 "-cxx" "/Users/sathish/Projects/Xamarin/RoamPayAPITest/RoamPayAPITest/bin/iPhone/Debug/RoamPayAPITest.exe"
Xamarin.iOS 7.0.4 Business Edition using framework: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk
warning MT3005: The dependency 'System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' of the assembly 'monotouch, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065' was not found. Please review the project's references.
warning MT3005: The dependency 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' of the assembly 'SwipeAPIBinding, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' was not found. Please review the project's references.
warning MT3005: The dependency 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' of the assembly 'SwipeAPIBinding, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' was not found. Please review the project's references.
warning MT3006: Could not compute a complete dependency map for the project. This will result in slower build times because Xamarin.iOS can't properly detect what needs to be rebuilt (and what does not need to be rebuilt). Please review previous warnings for more details.
Process exited with code 1, command:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++  -lz -lc++ -Wl,-pie  -miphoneos-version-min=7.0 -arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk  /Users/sathish/Projects/Xamarin/RoamPayAPITest/RoamPayAPITest/obj/iPhone/Debug/mtouch-cache/RoamPayAPITest.exe.armv7.o /Users/sathish/Projects/Xamarin/RoamPayAPITest/RoamPayAPITest/obj/iPhone/Debug/mtouch-cache/monotouch.dll.armv7.o /Users/sathish/Projects/Xamarin/RoamPayAPITest/RoamPayAPITest/obj/iPhone/Debug/mtouch-cache/mscorlib.dll.armv7.o /Users/sathish/Projects/Xamarin/RoamPayAPITest/RoamPayAPITest/obj/iPhone/Debug/mtouch-cache/SwipeAPIBinding.dll.armv7.o /Users/sathish/Projects/Xamarin/RoamPayAPITest/RoamPayAPITest/obj/iPhone/Debug/mtouch-cache/registrar.armv7.o /Users/sathish/Projects/Xamarin/RoamPayAPITest/RoamPayAPITest/obj/iPhone/Debug/mtouch-cache/main.armv7.o -force_load /Users/sathish/Projects/Xamarin/RoamPayAPITest/RoamPayAPITest/obj/iPhone/Debug/mtouch-cache/libSwiperAPI.a -o /Users/sathish/Projects/Xamarin/RoamPayAPITest/RoamPayAPITest/bin/iPhone/Debug/RoamPayAPITest.app/RoamPayAPITest -framework CFNetwork -framework Foundation -framework CoreGraphics -framework UIKit -framework CoreAudio -framework AudioToolbox -framework AVFoundation -framework MediaPlayer -lz -liconv -u _mono_pmip -u _monotouch_release_managed_ref -u _monotouch_create_managed_ref -u _monotouch_IntPtr_objc_msgSend_IntPtr -u _monotouch_IntPtr_objc_msgSendSuper_IntPtr -u _monotouch_log /Developer/MonoTouch/SDKs/MonoTouch.iphoneos.sdk/usr/lib/libmonoboehm-2.0.a /Developer/MonoTouch/SDKs/MonoTouch.iphoneos.sdk/usr/lib/libmonotouch-debug.a
Undefined symbols for architecture armv7:
  "std::ios_base::Init::Init()", referenced from:
      __GLOBAL__I_a in libSwiperAPI.a(DownSample.o)
      __GLOBAL__I_a in libSwiperAPI.a(FskController.o)
      __GLOBAL__I_a in libSwiperAPI.a(WavBuffer.o)
      __GLOBAL__I_a in libSwiperAPI.a(AE_ManchesterRealTimeDecoder.o)
      __GLOBAL__I_a in libSwiperAPI.a(AE_ManchesterState.o)
  "std::ios_base::Init::~Init()", referenced from:
      __GLOBAL__I_a in libSwiperAPI.a(DownSample.o)
      __GLOBAL__I_a in libSwiperAPI.a(FskController.o)
      __GLOBAL__I_a in libSwiperAPI.a(WavBuffer.o)
      __GLOBAL__I_a in libSwiperAPI.a(AE_ManchesterRealTimeDecoder.o)
      __GLOBAL__I_a in libSwiperAPI.a(AE_ManchesterState.o)
      __GLOBAL__I_a in libSwiperAPI.a(DownSample.o)
      __GLOBAL__I_a in libSwiperAPI.a(FskController.o)
      __GLOBAL__I_a in libSwiperAPI.a(WavBuffer.o)
      __GLOBAL__I_a in libSwiperAPI.a(AE_ManchesterRealTimeDecoder.o)
      __GLOBAL__I_a in libSwiperAPI.a(AE_ManchesterState.o)
      __GLOBAL__I_a in libSwiperAPI.a(DownSample.o)
      __GLOBAL__I_a in libSwiperAPI.a(FskController.o)
      __GLOBAL__I_a in libSwiperAPI.a(WavBuffer.o)
      __GLOBAL__I_a in libSwiperAPI.a(AE_ManchesterRealTimeDecoder.o)
      __GLOBAL__I_a in libSwiperAPI.a(AE_ManchesterState.o)
      __GLOBAL__I_a in libSwiperAPI.a(DownSample.o)
      __GLOBAL__I_a in libSwiperAPI.a(FskController.o)
      __GLOBAL__I_a in libSwiperAPI.a(WavBuffer.o)
      __GLOBAL__I_a in libSwiperAPI.a(AE_ManchesterRealTimeDecoder.o)
      __GLOBAL__I_a in libSwiperAPI.a(AE_ManchesterState.o)
      __GLOBAL__I_a in libSwiperAPI.a(DownSample.o)
      __GLOBAL__I_a in libSwiperAPI.a(FskController.o)
      __GLOBAL__I_a in libSwiperAPI.a(WavBuffer.o)
      __GLOBAL__I_a in libSwiperAPI.a(AE_ManchesterRealTimeDecoder.o)
      __GLOBAL__I_a in libSwiperAPI.a(AE_ManchesterState.o)
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
    error MT5210: Native linking failed, undefined symbol: std::ios_base::Init::Init().    
    Please verify that all the necessary frameworks have been referenced and native 
    libraries are properly linked in.

    error MT5210: Native linking failed, undefined symbol: std::ios_base::Init::~Init(). 
    Please verify that all the necessary frameworks have been referenced and native 
    libraries are properly linked in.

    error MT5202: Native linking failed. Please review the build log.

Could someone please help me regarding this.

Upvotes: 1

Views: 2552

Answers (1)

user3124624
user3124624

Reputation: 1216

Finally figured out the error!!

    [assembly: LinkWith (..., LinkerFlags = "-lstdc++ -lz" )]

In iOS Binding Projet

Options > Build > Compiler > Addition Arguments

    -cxx -gcc_flags "-stdlib=libstdc++ -L${ProjectDir} -lMylibrary -force_load ${ProjectDir}/libMylibrary.a”

In my demo application

Options > iOS Buidl > Addtional mtouch Arguments

    --gcc_flags="-stdlib=libstdc++"

By giving the proper flags in all the places it resolved my issue.

Upvotes: 1

Related Questions