mono / Embeddinator-4000

Tools to turn .NET libraries into native libraries that can be consumed on Android, iOS, Mac, Linux and other platforms.
MIT License
758 stars 95 forks source link

Creating iOS Framework for single platform is giving error. #789

Open DRK1004 opened 3 years ago

DRK1004 commented 3 years ago

Steps to Reproduce

I have .net library and trying to create a ios framework for single platform ( i.e either arm64 or x86_64) from that. To do that I used the either of below commands: objcgen XXX.iOS.dll --target=framework --platform=iOS --outdir=iOS -c --abi=arm64 -d --nativeexception

Expected Behavior

Single framework for arm64 should be created.

Actual Behavior

Observed error: error MT5209: Native linking error: warning: ignoring file XXXX.a, building for iOS Simulator-i386 but attempting to link with file built for iOS-arm64

Environment

Embeddinator-4000 v0.1 (0.4: 7664197) Found Mono 6.10.0.104 (between 5.4.1.7 and 5.4.1.7) Found Xamarin.iOS 13.20.2.2 (between 11.6.1.3 and 11.6.1.3) XCode 12.2 MacOS : Catalina version 10.15.7

Build Logs

Parsing assemblies... Parsed 'XXX.iOS.dll' Processing assemblies... 54 types found Generating binding code... Generated: iOS/bindings.h Generated: iOS/bindings-private.h Generated: iOS/bindings.m Generated: iOS/bindings.xml Generated: iOS/embeddinator.h Generated: iOS/glib.h Generated: iOS/mono_embeddinator.h Generated: iOS/mono-support.h Generated: iOS/objc-support.h Generated: iOS/glib.c Generated: iOS/mono_embeddinator.c Generated: iOS/objc-support.m Generated: iOS/Make.config Compiling binding code... Found Mono 6.10.0.104 (between 5.4.1.7 and 5.4.1.7) Found Xamarin.iOS 13.20.2.2 (between 11.6.1.3 and 11.6.1.3)

xcode-select -p xcrun clang -g -O0 -DNATIVEEXCEPTION -fobjc-arc -ObjC -Wall -arch arm64 -isysroot XXX/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk -miphoneos-version-min=8.0 -I/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/SDKs/MonoTouch.iphoneos.sdk/usr/include -DXAMARIN_IOS -DMONO_EMBEDDINATOR_DLL_EXPORT -c iOS/glib.c -o iOS/arm64/glib.o xcrun clang -g -O0 -DNATIVEEXCEPTION -fobjc-arc -ObjC -Wall -arch arm64 -isysroot XXX/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk -miphoneos-version-min=8.0 -I/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/SDKs/MonoTouch.iphoneos.sdk/usr/include -DXAMARIN_IOS -DMONO_EMBEDDINATOR_DLL_EXPORT -c iOS/mono_embeddinator.c -o iOS/arm64/mono_embeddinator.o xcrun clang -g -O0 -DNATIVEEXCEPTION -fobjc-arc -ObjC -Wall -arch arm64 -isysroot XXX/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk -miphoneos-version-min=8.0 -I/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/SDKs/MonoTouch.iphoneos.sdk/usr/include -DXAMARIN_IOS -DMONO_EMBEDDINATOR_DLL_EXPORT -c iOS/objc-support.m -o iOS/arm64/objc-support.o xcrun clang -g -O0 -DNATIVEEXCEPTION -fobjc-arc -ObjC -Wall -arch arm64 -isysroot XXX/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk -miphoneos-version-min=8.0 -I/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/SDKs/MonoTouch.iphoneos.sdk/usr/include -DXAMARIN_IOS -DMONO_EMBEDDINATOR_DLL_EXPORT -c iOS/bindings.m -o iOS/arm64/bindings.o xcrun ar cru iOS/arm64/XXX.iOS.a iOS/arm64/glib.o iOS/arm64/mono_embeddinator.o iOS/arm64/objc-support.o iOS/arm64/bindings.o xcrun --show-sdk-version --sdk iphoneos /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch --dev XXX.iOS --abi=arm64 --sdkroot XXUSERXX/Xcode_12.2.app --targetver 8.0 --dsym:false --msym:false --embeddinator XXX.iOS/bin/Release/XXX.iOS.dll -r:/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Xamarin.iOS.dll --sdk 14.2 --linksdkonly --xml=iOS/bindings.xml --registrar:static --cache XXX.iOS/bin/Release/iOS/iPhoneOS/build-cache --debug --assembly-build-target=@all=framework=XXX.iOS.framework --target-framework Xamarin.iOS,v1.0 "--gcc_flags=-force_load XXX.iOS.a" --marshal-managed-exceptions=throwobjectivecexception xcrun --show-sdk-version --sdk iphonesimulator /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch --sim XXX.iOS/bin/Release/iOS/iPhoneSimulator/XXX.iOS --abi= --sdkroot XXUSERXX/Xcode_12.2.app --targetver 8.0 --dsym:false --msym:false --embeddinator XXX.iOS/bin/Release/XXX.iOS.dll -r:/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Xamarin.iOS.dll --sdk 14.2 --linksdkonly --xml=iOS/bindings.xml --registrar:static --cache XXX.iOS/bin/Release/iOS/iPhoneSimulator/build-cache --debug --assembly-build-target=@all=framework=XXX.iOS.framework --target-framework Xamarin.iOS,v1.0 "--gcc_flags=-force_load XXX.iOS/bin/Release/iOS/iPhoneSimulator/XXX.iOS.a" --marshal-managed-exceptions=throwobjectivecexception Xamarin.iOS 13.20.2.2 (d16-7): 817b6f72a using framework: XXX/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.2.sdk warning MT0030: The executable name (XXX.iOS) and the app name (XXX.iOS) are different, this may prevent crash logs from getting symbolicated properly.

Process exited with code 1, command: error MT5209: Native linking error: warning: -pie being ignored. It is only used when linking a main executable

error MT5209: Native linking error: warning: ignoring file XXX.iOS/bin/Release/iOS/iPhoneSimulator/XXX.iOS.a, building for iOS Simulator-i386 but attempting to link with file built for iOS-arm64

error MT5210: Native linking failed, undefined symbol: _xamarin_embeddinator_initialize. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.

warning MT5215: References to 'System' might require additional -framework=XXX or -lXXX instructions to the native linker

warning MT5215: References to 'kernel32' might require additional -framework=XXX or -lXXX instructions to the native linker

warning MT5215: References to 'libdl' might require additional -framework=XXX or -lXXX instructions to the native linker

warning MT5215: References to 'MathNET.Numerics.OpenBLAS' might require additional -framework=XXX or -lXXX instructions to the native linker

warning MT5215: References to 'MathNet.Numerics.MKL' might require additional -framework=XXX or -lXXX instructions to the native linker

warning MT5215: References to 'MathNet.Numerics.CUDA' might require additional -framework=XXX or -lXXX instructions to the native linker

warning MT5215: References to 'kernel32' might require additional -framework=XXX or -lXXX instructions to the native linker

warning MT5215: References to 'Advapi32' might require additional -framework=XXX or -lXXX instructions to the native linker

error MT5201: Native linking failed. Please review the build log and the user flags provided to gcc: -force_load XXX.iOS/bin/Release/iOS/iPhoneSimulator/XXX.iOS.a

XXUSERXX/Xcode_12.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -framework Security -framework UIKit -framework Foundation -weak_framework CoreFoundation -weak_framework CFNetwork -weak_framework GSS -Xlinker -rpath -Xlinker @executable_path/ XXX.iOS/bin/Release/iOS/iPhoneSimulator/build-cache/i386/registrar.o XXX.iOS/bin/Release/iOS/iPhoneSimulator/build-cache/i386/main.o /Library/Frameworks/Xamarin.iOS.framework/Versions/13.20.2.2/SDKs/MonoTouch.iphonesimulator.sdk/usr/lib/libmonosgen-2.0.a /Library/Frameworks/Xamarin.iOS.framework/Versions/13.20.2.2/SDKs/MonoTouch.iphonesimulator.sdk/usr/lib/libxamarin-debug.a /Library/Frameworks/Xamarin.iOS.framework/Versions/13.20.2.2/SDKs/MonoTouch.iphonesimulator.sdk/usr/lib/libmono-native-compat.a -lsqlite3 -Wl,-pie -arch i386 -gdwarf-2 -std=c++14 -I/Library/Frameworks/Xamarin.iOS.framework/Versions/13.20.2.2/SDKs/MonoTouch.iphonesimulator.sdk/usr/include -isysroot XXX/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.2.sdk -Qunused-arguments -fobjc-legacy-dispatch -fobjc-abi-version=2 -mios-simulator-version-min=8.0 -lz -liconv -lz -o XXX.iOS/bin/Release/iOS/iPhoneSimulator/XXX.iOS/XXX.iOS -shared -install_name @rpath/XXX.iOS.framework/XXX.iOS -force_load XXX.iOS/bin/Release/iOS/iPhoneSimulator/XXX.iOS.a -u _SystemNative_ConvertErrorPlatformToPal -u _SystemNative_ConvertErrorPalToPlatform -u _SystemNative_StrErrorR -u _SystemNative_GetNonCryptographicallySecureRandomBytes -u _SystemNative_OpenDir -u _SystemNative_GetReadDirRBufferSize -u _SystemNative_ReadDirR -u _SystemNative_CloseDir -u _SystemNative_ReadLink -u _SystemNative_Stat2 -u _SystemNative_LStat2 -u _SystemNative_Symlink -u _SystemNative_CopyFile -u _SystemNative_GetEGid -u _SystemNative_GetEUid -u _SystemNative_MkDir -u _SystemNative_Rename -u _SystemNative_RmDir -u _SystemNative_UTimes -u _SystemNative_Unlink -u _xamarin_timezone_get_local_name -u _xamarin_timezone_get_data -u _xamarin_GetFolderPath -u _xamarin_log -u _xamarin_start_wwan -u _xamarin_find_protocol_wrapper_type -u _xamarin_get_block_descriptor -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 ld: warning: -pie being ignored. It is only used when linking a main executable ld: warning: ignoring file XXX.iOS/bin/Release/iOS/iPhoneSimulator/XXX.iOS.a, building for iOS Simulator-i386 but attempting to link with file built for iOS-arm64 Undefined symbols for architecture i386: "_xamarin_embeddinator_initialize", referenced from: native_to_managed_trampoline_1(objc_object, objc_selector, _MonoMethod, objc_object, unsigned int) in registrar.o native_to_managed_trampoline_2(objc_object, objc_selector*, _MonoMethod*, void, unsigned int) in registrar.o native_to_managed_trampoline_3(objc_object, objc_selector, _MonoMethod, unsigned int) in registrar.o native_to_managed_trampoline_4(objc_object, objc_selector, _MonoMethod*, bool, unsigned int) in registrar.o native_to_managed_trampoline_5(objc_object, objc_selector, _MonoMethod*, objc_object, unsigned int) in registrar.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

rolfbjarne commented 3 years ago

It's not possible to build for only simulator or device at the moment, you have to build for both (and select at least one architecture for each).

Relevant code: https://github.com/mono/Embeddinator-4000/blob/3bbe342df11ee62fc42674fcf4b94b993c5c216c/objcgen/embedder.cs#L359-L363

DRK1004 commented 3 years ago

XCFrameworks are required for Xcode 12.3+ . I have already created #790 for supporting XCFramework. As a workaround for now, I am trying to build one platform at a time, so that I can use those frameworks to create an XCFramework.

Let me know if you have any other suggestions for creating XCFrameworks.