Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding project errors: MT5209 : Native linking error relating to standard swift libraries. #17179

Closed
dk-jlew opened this issue Jan 10, 2023 · 11 comments
Labels
need-attention An issue requires our attention/response
Milestone

Comments

@dk-jlew
Copy link

dk-jlew commented Jan 10, 2023

Context: large Xamarin Forms 5 in which I'm trying to bind a native (xc)framework along with a bunch of dependencies (also xcframeworks which are included in the bundle but not bound). These are all delivered via a nuget-packaged Xamarin.iOS binding project. This has been working fine, but the native code is now pulling in a Swift Package which (either itself or one of its dependencies) is leading to multiple errors when building the app, like:

error MT5209 : Native linking error : warning: Could not find or use auto-linked library 'swiftCoreGraphics'
error MT5209 : Native linking error : warning: Could not find or use auto-linked library 'swiftSwiftOnoneSupport'
...etc...

...followed by many "symbol not found" linker errors which are presumably a consequence of the MT5209 errors above. I have followed the Microsoft guidance here and added the following to my NativeReference's <LinkerFlags>: (there are multiple native references, and I add this to each of them since I am not sure which ones might be the problem, but this redundancy seems(?) harmless):

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

IMPORTANT: A bare-bones Xamarin.iOS project builds/runs successfully when referencing/using the same nuget binding package. My real XF app has other binding projects as well, I'm not sure if there could be a conflict here, or what the difference might be.

Steps to Reproduce

  1. Build my big XF 5.0 solution, in the Debug | iPhoneSimulator configuration.

Expected Behavior

App builds sucessfully

Actual Behavior

iOS app project fails to build with the errors mentioned above

Environment

Version information
Visual Studio Community 2022 for Mac Preview
Version 17.5 Preview (17.5 build 437)
Installation UUID: 92d59e15-2ada-4ba7-870a-cadfaf4a5a3c

Runtime
.NET 7.0.0 (64-bit)
Architecture: Arm64

Roslyn (Language Service)
4.4.0-3.22461.4+8ab250290a4010c11a21521f78dbc87dbb7aac81

NuGet
Version: 6.3.1.1

.NET SDK (Arm64)
SDK: /usr/local/share/dotnet/sdk/7.0.100/Sdks
SDK Versions:
	7.0.100
	6.0.403
	6.0.402
	6.0.401
	6.0.400
	6.0.301
	6.0.300
	6.0.202
	6.0.201
MSBuild SDKs: /Applications/Visual Studio (Preview).app/Contents/MonoBundle/MSBuild/Current/bin/Sdks

.NET SDK (x64)
SDK Versions:
	6.0.403
	6.0.402
	6.0.401
	6.0.400
	6.0.301
	6.0.300
	6.0.105
	6.0.103
	5.0.408
	5.0.406
	3.1.425
	3.1.424
	3.1.423
	3.1.422
	3.1.420
	3.1.419
	3.1.418
	3.1.417

.NET Runtime (Arm64)
Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	7.0.0
	6.0.11
	6.0.10
	6.0.9
	6.0.8
	6.0.6
	6.0.5
	6.0.4
	6.0.3

.NET Runtime (x64)
Runtime: /usr/local/share/dotnet/x64/dotnet
Runtime Versions:
	6.0.11
	6.0.10
	6.0.9
	6.0.8
	6.0.6
	6.0.5
	6.0.3
	5.0.17
	5.0.15
	3.1.31
	3.1.30
	3.1.29
	3.1.28
	3.1.26
	3.1.25
	3.1.24
	3.1.23

Xamarin.Profiler
Version: 1.8.0.19
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

Updater
Version: 11

Apple Developer Tools
Xcode 14.1 (21534.1)
Build 14B47b

Xamarin.Mac
Version: 8.12.0.2 (Visual Studio Community)
Hash: 87f98a75e
Branch: d17-3
Build date: 2022-07-25 20:18:54-0400

Xamarin Designer
Version: 17.5.1.13
Hash: 14bdde937f
Branch: remotes/origin/d17-5
Build date: 2022-11-02 21:36:49 UTC

Xamarin.Android
Version: 13.1.0.1 (Visual Studio Community)
Commit: xamarin-android/d17-4/13ba222
Android SDK: /Users/jlew/Library/Android/sdk
	Supported Android versions:
		12.1 (API level 32)
		12.0 (API level 31)
		11.0 (API level 30)
		13.0 (API level 33)

SDK Command-line Tools Version: 5.0
SDK Platform Tools Version: 33.0.3
SDK Build Tools Version: 33.0.1

Build Information: 
Mono: a96bde9
Java.Interop: xamarin/java.interop/d17-4@fcc33ce2
SQLite: xamarin/sqlite/3.39.3@23e1ae7
Xamarin.Android Tools: xamarin/xamarin-android-tools/main@0be567a

Microsoft Build of OpenJDK
Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk
11.0.16.1
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Eclipse Temurin JDK
Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk
1.8.0.302
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Android SDK Manager
Version: 17.5.0.8
Hash: 6f27afd
Branch: remotes/origin/HEAD
Build date: 2022-11-02 21:36:54 UTC

Android Device Manager
Version: 0.0.0.1217
Hash: 6175224
Branch: main
Build date: 2022-11-02 21:36:54 UTC

Xamarin.iOS
Version: 16.0.0.72 (Visual Studio Community)
Hash: 6756a1146
Branch: release/6.0.4xx-xcode14
Build date: 2022-09-21 08:51:06-0400

Build Information
Release ID: 1705000437
Git revision: a5d0fb913c1ff781c80fe725a3e0511c34e26a08
Build date: 2022-11-02 21:34:22+00
Build branch: release-17.5
Build lane: release-17.5

Operating System
Mac OS X 12.6.1
Darwin 21.6.0 Darwin Kernel Version 21.6.0
    Thu Sep 29 20:13:56 PDT 2022
    root:xnu-8020.240.7~1/RELEASE_ARM64_T6000 arm64

Build Logs

Can't post these on github, available through secure channel on request.

Example Project (If Possible)

The full project is difficult to provide... I can provide the problematic nuget package and bare-bones Xamarin.iOS project which does build easily enough.

@dk-jlew
Copy link
Author

dk-jlew commented Jan 11, 2023

This seems extremely similar to this issue from React Native, but I have no way to try their solution since we don't have direct control of the Xcode project.

@dk-jlew
Copy link
Author

dk-jlew commented Jan 13, 2023

Another update:
We have narrowed this down to a conflict with the Xamarin Firebase components. Someone else has apparently had the same issue:
xamarin/GoogleApisForiOSComponents#488

@dk-jlew
Copy link
Author

dk-jlew commented Jan 17, 2023

@rolfbjarne Do you have any insight into this, or can I provide more info?

@rolfbjarne
Copy link
Member

@rolfbjarne rolfbjarne added the need-info Waiting for more information before the bug can be investigated label Jan 18, 2023
@ghost
Copy link

ghost commented Jan 18, 2023

Hi @dk-jlew. We have added the "need-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@rolfbjarne rolfbjarne added this to the Future milestone Jan 18, 2023
@dk-jlew
Copy link
Author

dk-jlew commented Jan 18, 2023

Sure, here you go (this is the minimal repro app, not the real one. It is referencing Xamarin.Firebase.iOS.RemoteConfig and my own package. If I remove the Firebase package, everything builds and works fine.)

(Edit: Updated with a less confusing build that doesn't have some test code I was messing around with)
msbuild 2.binlog.zip

@ghost ghost added need-attention An issue requires our attention/response and removed need-info Waiting for more information before the bug can be investigated labels Jan 18, 2023
@rolfbjarne
Copy link
Member

@dk-jlew can you try adding -gcc_flags "-L /usr/lib/swift" in the additional mtouch arguments in the project's iOS Build properties? If that doesn't work, please attach another build log.

@dk-jlew
Copy link
Author

dk-jlew commented Jan 19, 2023

@rolfbjarne That didn't work by itself (though it seemed to reduce the # of errors). BUT, this did:
-gcc_flags "-L /usr/lib/swift -L /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/$(Platform)"

It seems like you need both, for reasons I don't understand.
Do you know if there's an msbuild property that points to the xcode toolchain root that the rest of the build process is using? Thanks!

@rolfbjarne
Copy link
Member

rolfbjarne commented Jan 19, 2023

The property _SdkDevPath will be set to /Applications/Xcode.app/Contents/Developer, so you could add this to the csproj:

-gcc_flags "-L /usr/lib/swift -L $(_SdkDevPath)/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/$(Platform)"

@dk-jlew
Copy link
Author

dk-jlew commented Jan 19, 2023 via email

@dk-jlew
Copy link
Author

dk-jlew commented Jan 19, 2023

I had to do it like this due to the way MtouchExtraArgs and _BundlerArguments are intertwined. Kinda ugly, but it works:

<Target Name="CreateMtouchExtraArgs" AfterTargets="_DetectSdkLocations">
        <PropertyGroup>
            <MtouchExtraArgs>$(MtouchExtraArgs) -v -v -v -v -gcc_flags "-L /usr/lib/swift -L $(_SdkDevPath)/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/$(Platform)"</MtouchExtraArgs>
            <_BundlerArguments Condition="'$(_PlatformName)' != 'macOS'">$(MtouchExtraArgs)</_BundlerArguments>
        </PropertyGroup>
        <Message Importance="high" Text="MtouchExtraArgs is $(MtouchExtraArgs)" />
 </Target>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
need-attention An issue requires our attention/response
Projects
None yet
Development

No branches or pull requests

2 participants