xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.46k stars 512 forks source link

Errors on building maui ios app with xcframework with static library #21487

Open damiand2 opened 3 days ago

damiand2 commented 3 days ago

Apple platform

iOS

Framework version

net8.0-*

Affected platform version

.NET 8.0.403

Description

  1. downloaded static library (libTapLinxLibrary.a) with headers
  2. created xcframework using xcodebuild -create-xcframework option
  3. created maui ios binding library with reference to xcframework:
<NativeReference Include="taplinkx.xcframework">
        <Kind>Framework</Kind>
        <SmartLink>True</SmartLink>
        <ForceLoad>False</ForceLoad>
    </NativeReference>
  1. created main maui app with reference to that binding library
  2. when building app, it ends with error: ld: framework 'ios-arm64' not found

Steps to Reproduce

as described in descroption section

Did you find any workaround?

no workaround - when using raw static library with

<NativeReference Include="libTapLinxLibrary.a">
            <Kind>Static</Kind>
            <ForceLoad>False</ForceLoad>
            <IsCxx>False</IsCxx>
            <SmartLink>True</SmartLink>
            <Frameworks></Frameworks>
        </NativeReference>

I get different errors:

Undefined symbols for architecture arm64:
         "_IOSArray_throwOutOfBoundsWithMsg", referenced from:
             xyxVp1J in libTapLinxLibrary.a[28](DESDiversificationCryptogram-a00680cd9a9a622f6e50414797da12e6.o)
             xyxVp1J in libTapLinxLibrary.a[28](DESDiversificationCryptogram-a00680cd9a9a622f6e50414797da12e6.o)
             xyxVp1J in libTapLinxLibrary.a[28](DESDiversificationCryptogram-a00680cd9a9a622f6e50414797da12e6.o)
             xyxVp1J in libTapLinxLibrary.a[28](DESDiversificationCryptogram-a00680cd9a9a622f6e50414797da12e6.o)
             xyxVp1J in libTapLinxLibrary.a[28](DESDiversificationCryptogram-a00680cd9a9a622f6e50414797da12e6.o)
             hEO in libTapLinxLibrary.a[36](MFPReadBinaryCommand-5800826da77fff332ed968970611ec4c.o)
             _JOyve8_ in libTapLinxLibrary.a[37](MFPSetConfigDataHelper-ace1dc9e6c10933b572c69380f8a29dc.o)
             _JOyve8_ in libTapLinxLibrary.a[37](MFPSetConfigDataHelper-ace1dc9e6c10933b572c69380f8a29dc.o)
             _JOyve8_ in libTapLinxLibrary.a[37](MFPSetConfigDataHelper-ace1dc9e6c10933b572c69380f8a29dc.o)
             ...
         "_IOSClass_arrayType", referenced from:
             _is6qegn in libTapLinxLibrary.a[38](NTAG424DNATTFileSettingsHelper-fb10e721f7cd0149de301db9d67141f9.o)
             _is6qegn in libTapLinxLibrary.a[38](NTAG424DNATTFileSettingsHelper-fb10e721f7cd0149de301db9d67141f9.o)
             _is6qegn in libTapLinxLibrary.a[38](NTAG424DNATTFileSettingsHelper-fb10e721f7cd0149de301db9d67141f9.o)
             _is6qegn in libTapLinxLibrary.a[38](NTAG424DNATTFileSettingsHelper-fb10e721f7cd0149de301db9d67141f9.o)
             _is6qegn in libTapLinxLibrary.a[38](NTAG424DNATTFileSettingsHelper-fb10e721f7cd0149de301db9d67141f9.o)
             _is6qegn in libTapLinxLibrary.a[38](NTAG424DNATTFileSettingsHelper-fb10e721f7cd0149de301db9d67141f9.o)
             _is6qegn in libTapLinxLibrary.a[38](NTAG424DNATTFileSettingsHelper-fb10e721f7cd0149de301db9d67141f9.o)
             _is6qegn in libTapLinxLibrary.a[38](NTAG424DNATTFileSettingsHelper-fb10e721f7cd0149de301db9d67141f9.o)
             _is6qegn in libTapLinxLibrary.a[38](NTAG424DNATTFileSettingsHelper-fb10e721f7cd0149de301db9d67141f9.o)
             _is6qegn in libTapLinxLibrary.a[38](NTAG424DNATTFileSettingsHelper-fb10e721f7cd0149de301db9d67141f9.o)
             _is6qegn in libTapLinxLibrary.a[38](NTAG424DNATTFileSettingsHelper-fb10e721f7cd0149de301db9d67141f9.o)
             ...
         "_IOSClass_fromClass", referenced from:
             _fUexgi9W in libTapLinxLibrary.a[29](VirtualCardTypeIdentifier-ca903203ed55ee5ec56a557cddd60077.o)
             _fUexgi9W in libTapLinxLibrary.a[29](VirtualCardTypeIdentifier-ca903203ed55ee5ec56a557cddd60077.o)
             _Yhy_G in libTapLinxLibrary.a[35](EV3CMFCState-1ea08d0613728dd5547d98ddd83b25c2.o)
             _wSgf7 in libTapLinxLibrary.a[37](MFPSetConfigDataHelper-ace1dc9e6c10933b572c69380f8a29dc.o)
             _pt3XpuU8 in libTapLinxLibrary.a[42](MFPWriteRecordCommand-9aee92c76e527039ed9245b24905c80a.o)
             _iILaq in libTapLinxLibrary.a[45](CardType-bf7900bc525aa390599f79995909813d.o)
             _iILaq in libTapLinxLibrary.a[45](CardType-bf7900bc525aa390599f79995909813d.o)
             ...

and the list goes on...

Build logs

msbuild.zip

rolfbjarne commented 2 days ago

It's a static library, so in your NativeReference item you need to set Kind=Static:

<NativeReference Include="taplinkx.xcframework">
    <Kind>Static</Kind>
    <SmartLink>True</SmartLink>
    <ForceLoad>False</ForceLoad>
</NativeReference>

Can you try that and see if it works for you?

damiand2 commented 2 days ago

@rolfbjarne - thanks for your answer. Unfortunately after changing to static i get the same errors as when consuming raw static library - 'undefined symbols for architecture arm64'. Attached build log. msbuild.zip

rolfbjarne commented 2 days ago

There can be any number of reasons for those failures:

What are the instructions to use this library from an Xcode project?

damiand2 commented 2 days ago

@rolfbjarne - documentation states "The J2ObjC library is used for converting the Java source code into Objective C, there are some dependency library and header which are to be included in the build settings". I will try to add them to the macos and let you know if this changes anything

damiand2 commented 1 day ago

hi again @rolfbjarne :) i managed to install and configure missing dependencies on macos, now when i try to build app i get error: clang++ exited with code 1: Apple clang version 16.0.0 (clang-1600.0.26.3) Target: arm64-apple-darwin23.6.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -dynamic -arch arm64 -dead_strip -exported_symbols_list obj/Debug/net8.0-ios/ios-arm64/device-builds/iphone14.7-18.0.1/mtouch-symbols.list -force_load C:/Users/xxx/source/repos/MobileFacilityApp/Taplinx.iOS/bin/Debug/net8.0-ios/Taplinx.iOS.resources/taplinkx.xcframework/ios-arm64/libTapLinxLibrary.a -platform_version ios 14.0.0 18.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.0.sdk -mllvm -enable-linkonceodr-outlining -o /Users/xxx/Library/Caches/Xamarin/mtbs/builds/MobileFacilityApp/4b2d803b751cc60ac63dbbddcfa799750f94e1d224e1ea40cfbb762cddb9f7e0/obj/Debug/net8.0-ios/ios-arm64/nativelibraries/MobileFacilityApp -L/Users/xxx/Projects/j2objc-2.7/lib/ -L/usr/lib/swift -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos -framework Security -liconv -licucore -lz -ljre_emul -ljre_util /Users/xxx/Library/Caches/Xamarin/mtbs/builds/MobileFacilityApp/4b2d803b751cc60ac63dbbddcfa799750f94e1d224e1ea40cfbb762cddb9f7e0/obj/Debug/net8.0-ios/ios-arm64/nativelibraries/aot-output/arm64/aot-instances.dll.o /Users/xxx/Library/Caches/Xamarin/mtbs/builds/MobileFacilityApp/4b2d803b751cc60ac63dbbddcfa799750f94e1d224e1ea40cfbb762cddb9f7e0/obj/Debug/net8.0-ios/ios-arm64/nativelibraries/aot-output/arm64/System.Private.CoreLib.dll.o "/Users/xxx/Library/Caches/Xamarin/mtbs/builds/MobileFacilityApp/4b2d803b751cc60ac63dbbddcfa799750f94e1d224e1ea40cfbb762cddb9f7e0/C:/Program Files/dotnet/packs/Microsoft.iOS.Runtime.ios-arm64.net8.0_18.0/18.0.8303/runtimes/ios-arm64/native/libxamarin-dotnet-debug.a" "/Users/xxx/Library/Caches/Xamarin/mtbs/builds/MobileFacilityApp/4b2d803b751cc60ac63dbbddcfa799750f94e1d224e1ea40cfbb762cddb9f7e0/C:/Program Files/dotnet/packs/Microsoft.NETCore.App.Runtime.Mono.ios-arm64/8.0.10/runtimes/ios-arm64/native/libSystem.Globalization.Native.a" "/Users/xxx/Library/Caches/Xamarin/mtbs/builds/MobileFacilityApp/4b2d803b751cc60ac63dbbddcfa799750f94e1d224e1ea40cfbb762cddb9f7e0/C:/Program Files/dotnet/packs duplicate symbol '_tapLinxLibrary' in: C:/Users/xxx/repos/MobileFacilityApp/Taplinx.iOS/bin/Debug/net8.0-ios/Taplinx.iOS.resources/taplinkx.xcframework/ios-arm64/libTapLinxLibrary.a[16](TL_NTAG_223DNA.o) C:/Users/xxx/source/repos/MobileFacilityApp/Taplinx.iOS/bin/Debug/net8.0-ios/Taplinx.iOS.resources/taplinkx.xcframework/ios-arm64/libTapLinxLibrary.a[14](TL_UltralightAES.o) C:/Users/xxx/source/repos/MobileFacilityApp/Taplinx.iOS/bin/Debug/net8.0-ios/Taplinx.iOS.resources/taplinkx.xcframework/ios-arm64/libTapLinxLibrary.a[3](TL_DESFireEV2.o) C:/Users/xxx/source/repos/MobileFacilityApp/Taplinx.iOS/bin/Debug/net8.0-ios/Taplinx.iOS.resources/taplinkx.xcframework/ios-arm64/libTapLinxLibrary.a[22](TL_NTAG_223DNA_SD.o) C:/Users/xxx/source/repos/MobileFacilityApp/Taplinx.iOS/bin/Debug/net8.0-ios/Taplinx.iOS.resources/taplinkx.xcframework/ios-arm64/libTapLinxLibrary.a[21](TL_DESFireEV3.o) C:/Users/xxx/source/repos/MobileFacilityApp/Taplinx.iOS/bin/Debug/net8.0-ios/Taplinx.iOS.resources/taplinkx.xcframework/ios-arm64/libTapLinxLibrary.a[20](TL_NTAG_224DNA_SD.o) C:/Users/xxx/source/repos/MobileFacilityApp/Taplinx.iOS/bin/Debug/net8.0-ios/Taplinx.iOS.resources/taplinkx.xcframework/ios-arm64/libTapLinxLibrary.a[18](TL_NTAG_224DNA.o) ld: 1 duplicate symbols clang++: error: linker command failed with exit code 1 (use -v to see invocation)

Using nm on libTapLinxLibrary.a and grepping for _tapLinxLibrary i get 7 references: ---------------- D _tapLinxLibrary ---------------- D _tapLinxLibrary ---------------- D _tapLinxLibrary ---------------- D _tapLinxLibrary ---------------- D _tapLinxLibrary ---------------- D _tapLinxLibrary ---------------- D _tapLinxLibrary libTapLinxLibrary.a:MFClassic-5e42ba37eb30d20b01f915d605184521.o: no symbols

msbuild.zip

rolfbjarne commented 7 hours ago

Try setting SmartLink=True and ForceLoad=false in your NativeReference item:

<NativeReference Include="libTapLinxLibrary.a">
    <Kind>Static</Kind>
    <SmartLink>True</SmartLink>
    <ForceLoad>False</ForceLoad>
    <IsCxx>False</IsCxx>
    <Frameworks>Security.framework</Frameworks>
    <LinkerFlags>-lz -L "/Users/damiandekoszczak/Projects/j2objc-2.7/lib/" -ljre_emul -ljre_util -v</LinkerFlags>
    <!--<Frameworks>libiconv.tbd libicucore.tbd libz.tbd Security.framework</Frameworks>-->
    <!--<LinkerFlags>-L "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/" -L "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos" -Wl,-rpath -Wl,@executable_path/Frameworks</LinkerFlags>-->
</NativeReference>