4

我正在尝试通过创建 Xamarin.iOS 绑定项目来使用本机目标 C 框架。绑定项目本身编译得很好,但是,引用它的 iOS 应用程序项目,每当我添加一些使用此绑定库的代码行时,都不会构建。错误是:

Error MT5202: Native linking failed. Please review the build log. (MT5202)

我曾在互联网上寻找过,包括这里,看到很多人有类似的问题,但这与编译图书馆的架构有关。所以可以肯定的是,我已经检查了命令工具中的库,结果是我应该让它在模拟器和真实设备中都工作。命令和输出是:

# xcrun -sdk iphoneos lipo -info libDTEFMobile.a
Architectures in the fat file: libDTEFMobile.a are: armv7 armv7s i386 

# file libDTEFMobile.a
libDTEFMobile.a: Mach-O universal binary with 3 architectures
libDTEFMobile.a (for architecture armv7):   current ar archive random library
libDTEFMobile.a (for architecture cputype (12) cpusubtype (11)):    current ar archive random library
libDTEFMobile.a (for architecture i386):    current ar archive random library

所以为了确定,我已经在绑定项目中检查了我的 linkwith.cs 文件,这就是我所拥有的:

[assembly: LinkWith ("libDTEFMobile.a", LinkTarget.ArmV7 | LinkTarget.ArmV7s | LinkTarget.Simulator, ForceLoad = true)]

我的构建输出的最后日志是:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang  -arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk -Qunused-arguments -miphoneos-version-min=7.0 -c -o /Users/gutemberg/Projects/M2.Mobile/M2.Mobile.iOS/obj/iPhone/Debug/mtouch-cache/mscorlib.dll.armv7.o -x assembler /Users/gutemberg/Projects/M2.Mobile/M2.Mobile.iOS/obj/iPhone/Debug/mtouch-cache/mscorlib.dll.armv7.s
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang  -Wl,-pie  -miphoneos-version-min=7.0 -arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk  /Users/gutemberg/Projects/M2.Mobile/M2.Mobile.iOS/obj/iPhone/Debug/mtouch-cache/M2MobileiOS.exe.armv7.o /Users/gutemberg/Projects/M2.Mobile/M2.Mobile.iOS/obj/iPhone/Debug/mtouch-cache/monotouch.dll.armv7.o /Users/gutemberg/Projects/M2.Mobile/M2.Mobile.iOS/obj/iPhone/Debug/mtouch-cache/mscorlib.dll.armv7.o /Users/gutemberg/Projects/M2.Mobile/M2.Mobile.iOS/obj/iPhone/Debug/mtouch-cache/M2.Mobile.Bindings.iOS.dll.armv7.o /Users/gutemberg/Projects/M2.Mobile/M2.Mobile.iOS/obj/iPhone/Debug/mtouch-cache/registrar.armv7.o /Users/gutemberg/Projects/M2.Mobile/M2.Mobile.iOS/obj/iPhone/Debug/mtouch-cache/main.armv7.o -force_load /Users/gutemberg/Projects/M2.Mobile/M2.Mobile.iOS/obj/iPhone/Debug/mtouch-cache/libDTEFMobile.a -o /Users/gutemberg/Projects/M2.Mobile/M2.Mobile.iOS/bin/iPhone/Debug/M2MobileiOS.app/M2MobileiOS -framework CFNetwork -framework Foundation -framework UIKit -framework CoreGraphics -lz -liconv -u _mono_pmip -u _monotouch_release_managed_ref -u _monotouch_create_managed_ref -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
Process exited with code 1, command:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang  -Wl,-pie  -miphoneos-version-min=7.0 -arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk  /Users/gutemberg/Projects/M2.Mobile/M2.Mobile.iOS/obj/iPhone/Debug/mtouch-cache/M2MobileiOS.exe.armv7.o /Users/gutemberg/Projects/M2.Mobile/M2.Mobile.iOS/obj/iPhone/Debug/mtouch-cache/monotouch.dll.armv7.o /Users/gutemberg/Projects/M2.Mobile/M2.Mobile.iOS/obj/iPhone/Debug/mtouch-cache/mscorlib.dll.armv7.o /Users/gutemberg/Projects/M2.Mobile/M2.Mobile.iOS/obj/iPhone/Debug/mtouch-cache/M2.Mobile.Bindings.iOS.dll.armv7.o /Users/gutemberg/Projects/M2.Mobile/M2.Mobile.iOS/obj/iPhone/Debug/mtouch-cache/registrar.armv7.o /Users/gutemberg/Projects/M2.Mobile/M2.Mobile.iOS/obj/iPhone/Debug/mtouch-cache/main.armv7.o -force_load /Users/gutemberg/Projects/M2.Mobile/M2.Mobile.iOS/obj/iPhone/Debug/mtouch-cache/libDTEFMobile.a -o /Users/gutemberg/Projects/M2.Mobile/M2.Mobile.iOS/bin/iPhone/Debug/M2MobileiOS.app/M2MobileiOS -framework CFNetwork -framework Foundation -framework UIKit -framework CoreGraphics -lz -liconv -u _mono_pmip -u _monotouch_release_managed_ref -u _monotouch_create_managed_ref -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:
  "_EAAccessoryDidConnectNotification", referenced from:
      -[PaxMessager connectByBT] in libDTEFMobile.a(DTEFMobile)
  "_EAAccessoryDidDisconnectNotification", referenced from:
      -[PaxMessager connectByBT] in libDTEFMobile.a(DTEFMobile)
  "_OBJC_CLASS_$_EAAccessoryManager", referenced from:
      objc-class-ref in libDTEFMobile.a(DTEFMobile)
  "_OBJC_CLASS_$_EASession", referenced from:
      objc-class-ref in libDTEFMobile.a(DTEFMobile)
     (maybe you meant: _OBJC_CLASS_$_EASessionController)
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

error MT5202: Native linking failed. Please review the build log.
  at MonoTouch.Application.NativeLink () [0x00000] in <filename unknown>:0 
  at MonoTouch.Application.BuildApp () [0x00000] in <filename unknown>:0 
  at MonoTouch.Application.Build () [0x00000] in <filename unknown>:0 
  at MTouch.Main2 (System.String[] args) [0x00000] in <filename unknown>:0 
  at MTouch.Main (System.String[] args) [0x00000] in <filename unknown>:0 

---------------------- Done ----------------------

而且,我的 Xamarin.iOS 版本详细信息是:

Xamarin Studio
Version 4.0.12 (build 3)
Installation UUID: 7348d641-ed6d-4c8a-b59a-116674e06dfd
Runtime:
    Mono 3.2.3 ((no/8d3b4b7)
    GTK 2.24.20
    GTK# (2.12.0.0)
    Package version: 302030000

Apple Developer Tools
Xcode 5.0 (3332.25)
Build 5A1413

Xamarin.iOS
Version: 7.0.0.11 (Trial Edition)
Hash: aa35ba3
Branch: 
Build date: 2013-18-09 16:42:48-0400

Build Information
Release ID: 400120003
Git revision: 593d7acb1cb78ceeeb482d5133cf1fe514467e39
Build date: 2013-08-07 20:30:53+0000
Xamarin addins: 25a0858b281923e666b09259ad4746b774e0a873

Operating System
Mac OS X 10.8.5
Darwin Gutembergs-MacBook-Pro.local 12.5.0 Darwin Kernel Version 12.5.0
    Mon Jul 29 16:33:49 PDT 2013
    root:xnu-2050.48.11~1/RELEASE_X86_64 x86_64

有人知道我是如何让这个工作的吗?我正在尝试使用的库链接到 ExternalAccessory.framework,因此我可以访问蓝牙设备,这就是日志似乎抱怨的内容......

感谢您的帮助,非常感谢...

古腾堡

4

1 回答 1

3

您必须与 ExternalAccessory 框架链接,Xamarin.iOS 无法自动确定这需要为您的绑定完成。

这很容易做到,只需将 Frameworks 属性添加到绑定项目中的 LinkWith 属性即可:

[LinkWith (..., Frameworks = "ExternalAccessory")]
于 2013-09-20T22:38:39.273 回答