将Swift库ATInternet绑定到iOS项目编译错误:本机链接失败

时间:2018-02-19 14:35:05

标签: c# swift xamarin xamarin.ios xamarin-binding

我正在尝试将新版本的ATInternet ATTracker (现在在 Swift 中)绑定到 Xamarin.Forms < / strong>项目。

我关注this tutorial并开始使用此project sample。我用ATInternet库替换了原生引用。然后,我在Mac上使用Sharpie生成 ApiDefinition.cs 文件(并将其简化为最小版本,因此它只能初始化默认跟踪器)。我得到以下 ApiDefinition.cs 文件:

//// @interface ATInternet : NSObject
[BaseType(typeof(NSObject))]
//[DisableDefaultCtor]
public interface ATInternet
{
    // @property (readonly, nonatomic, strong) Tracker * _Nonnull defaultTracker;
    [Export("defaultTracker", ArgumentSemantic.Strong)]
    Tracker DefaultTracker { get; }

    // @property (readonly, nonatomic, strong, class) ATInternet * _Nonnull sharedInstance;
    [Static]
    [Export("sharedInstance")]
    ATInternet SharedInstance();

    // -(Tracker * _Nonnull)tracker:(NSString * _Nonnull)name __attribute__((warn_unused_result));
    [Export("tracker:")]
    Tracker Tracker(string name);
}

// @interface Tracker : NSObject
[BaseType(typeof(NSObject))]
public interface Tracker
{
    // -(void)setConfig:(NSDictionary<NSString *,NSString *> * _Nonnull)configuration override:(BOOL)override sync:(BOOL)sync completionHandler:(void (^ _Nullable)(BOOL))completionHandler;
    [Export("setConfig:override:sync:completionHandler:")]
    void SetConfig(NSDictionary<NSString, NSString> configuration, bool @override, bool sync, [NullAllowed] Action<bool> completionHandler);
}

然后在我的Xamarin.iOS项目中使用它:

public partial class ViewController : UIViewController
{
    protected ViewController(IntPtr handle) : base(handle) {}

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();

        var instance = XamarinBindingLibrary.ATInternet.SharedInstance();
        //var tracker = instance.DefaultTracker;
    }
}

但是每当我尝试编译项目时,我都会收到以下错误:

2>  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++  -framework Foundation -framework QuartzCore -framework CloudKit -framework UIKit -framework CoreGraphics -F /Users/sfdigital/Library/Caches/Xamarin/mtbs/builds/SampleUsing/1978f5377351d84fde88f310ab60b786/obj/iPhoneSimulator/Debug/mtouch-cache -framework Tracker -F /Users/sfdigital/Library/Caches/Xamarin/mtbs/builds/SampleUsing/1978f5377351d84fde88f310ab60b786/obj/iPhoneSimulator/Debug/mtouch-cache -framework TrackerExtension -weak_framework Intents -weak_framework CFNetwork -Xlinker -rpath -Xlinker @executable_path/Frameworks /Users/sfdigital/Library/Caches/Xamarin/mtbs/builds/SampleUsing/1978f5377351d84fde88f310ab60b786/obj/iPhoneSimulator/Debug/mtouch-cache/x86_64/main.o /Library/Frameworks/Xamarin.iOS.framework/Versions/11.6.1.4/SDKs/MonoTouch.iphonesimulator.sdk/usr/lib/libmonosgen-2.0.a /Library/Frameworks/Xamarin.iOS.framework/Versions/11.6.1.4/SDKs/MonoTouch.iphonesimulator.sdk/usr/lib/libxamarin-debug.a -force_load /Library/Frameworks/Xamarin.iOS.framework/Versions/11.6.1.4/SDKs/MonoTouch.iphonesimulator.sdk/usr/lib/libapp.a -Wl,-pie -arch x86_64 -gdwarf-2 -std=c99 -I/Library/Frameworks/Xamarin.iOS.framework/Versions/11.6.1.4/SDKs/MonoTouch.iphonesimulator.sdk/usr/include -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.2.sdk -Qunused-arguments -fobjc-legacy-dispatch -fobjc-abi-version=2 -mios-simulator-version-min=9.3 -lz -liconv -o /Users/sfdigital/Library/Caches/Xamarin/mtbs/builds/SampleUsing/1978f5377351d84fde88f310ab60b786/bin/iPhoneSimulator/Debug/SampleUsing.app/SampleUsing -dead_strip -u _xamarin_timezone_get_data -u _xamarin_log -u _UIApplicationMain -u _xamarin_get_block_descriptor -u '_OBJC_CLASS_$_ATInternet' -u '_OBJC_CLASS_$_Tracker' -u _mono_pmip -u _xamarin_dyn_objc_msgSend -u _xamarin_dyn_objc_msgSendSuper -u _xamarin_dyn_objc_msgSend_stret -u _xamarin_dyn_objc_msgSendSuper_stret
2>  Undefined symbols for architecture x86_64:
2>    "_OBJC_CLASS_$_Tracker", referenced from:
2>       -u command line option
2>    "_OBJC_CLASS_$_ATInternet", referenced from:
2>       -u command line option
2>  ld: symbol(s) not found for architecture x86_64
2>  clang: error: linker command failed with exit code 1 (use -v to see invocation)
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(777,3): error : Native linking failed, undefined Objective-C class: Tracker. The symbol '_OBJC_CLASS_$_Tracker' could not be found in any of the libraries or frameworks linked with your application.
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(777,3): error : Native linking failed, undefined Objective-C class: ATInternet. The symbol '_OBJC_CLASS_$_ATInternet' could not be found in any of the libraries or frameworks linked with your application.
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(777,3): error : Native linking failed. Please review the build log.

我在github here

上推送了我的项目

我怎么能摆脱这个错误?

0 个答案:

没有答案