Bug 15638 - App fails to build with error MT5202: Native linking failed with Linker set to Don't Link
Summary: App fails to build with error MT5202: Native linking failed with Linker set t...
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 6.4.4
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2013-10-23 20:53 UTC by Jon Goldberger [MSFT]
Modified: 2013-10-23 21:20 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Working Xcode project (153.64 KB, application/zip)
2013-10-23 20:56 UTC, Jon Goldberger [MSFT]
Non-Working Xamarin.iOS app. (132.48 KB, application/zip)
2013-10-23 20:57 UTC, Jon Goldberger [MSFT]
Screenshot of Xcode (31.10 KB, image/png)
2013-10-23 21:13 UTC, Sebastien Pouliot

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Comment 1 Jon Goldberger [MSFT] 2013-10-23 20:54:34 UTC
I have a working XCode version using this external .a file which works
fine. But when I created the binding, it compiled well. But as soon as I
added a reference of this static library to iPad Project it gave compiled
errors. XCODE working version and XAMARIN non-working version attached.


Compiling interface definitions
/Applications/Xcode.app/Contents/Developer/usr/bin/ibtool --errors
--warnings --notices --output-format human-readable-text --compile
2013-10-20 00:50:21.175 Interface Builder Cocoa Touch Tool[18794:303]
CFPreferences: user home directory at
is unavailable. User domains will be volatile.
Build complete -- 0 errors, 1 warning

Compiling to native code
/Developer/MonoTouch/usr/bin/mtouch -sdkroot
"/Applications/Xcode.app/Contents/Developer" --cache
--nomanifest --nosign -dev
-r "/Developer/MonoTouch/usr/lib/mono/2.1/System.dll" -r
"/Developer/MonoTouch/usr/lib/mono/2.1/System.Xml.dll" -r
"/Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll" -r
"/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll" -linksdkonly -sdk
"7.0" -targetver "7.0" --abi=armv7
Xamarin.iOS 7.0.2 Business Edition using framework:
warning MT3005: The dependency 'mscorlib, Version=, Culture=neutral,
PublicKeyToken=b77a5c561934e089' of the assembly 'MagReadBindings,
Version=, Culture=neutral, PublicKeyToken=null' was not found.
Please review the project's references.
warning MT3006: Could not compute a complete dependency map for the
project. This will result in slower build times because Xamarin.iOS can't
properly detect what needs to be rebuilt (and what does not need to be
rebuilt). Please review previous warnings for more details.
Process exited with code 1, command:
-Wl,-pie -miphoneos-version-min=7.0 -arch armv7 -isysroot
-framework CFNetwork -framework Foundation -framework UIKit -framework
CoreGraphics -framework AudioToolbox -framework CoreAudio -lz -liconv -u
_monotouch_release_managed_ref -u _monotouch_create_managed_ref -u
Undefined symbols for architecture armv7:
"_AVAudioSessionCategoryPlayAndRecord", referenced from:
-[AudioHelper checkAndPrepareCategoryForRecording] in
-[AudioHelper resetCategory] in libiMagRead.a(audioHelper.o)
"_AVAudioSessionCategoryPlayback", referenced from:
-[AudioHelper resetCategory] in libiMagRead.a(audioHelper.o)
"_OBJC_CLASS_$_AVAudioSession", referenced from:
objc-class-ref in libiMagRead.a(audioHelper.o)
"_OBJC_CLASS_$_MPMusicPlayerController", referenced from:
objc-class-ref in libiMagRead.a(audioHelper.o)
"_OBJC_CLASS_$_MPVolumeView", referenced from:
objc-class-ref in libiMagRead.a(audioHelper.o)
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see

error MT5202: Native linking failed. Please review the build log.
Comment 2 Jon Goldberger [MSFT] 2013-10-23 20:56:47 UTC
Created attachment 5222 [details]
Working Xcode project

Had to change the library search path as the developers project folder in their user folder was entered.
Comment 3 Jon Goldberger [MSFT] 2013-10-23 20:57:34 UTC
Created attachment 5223 [details]
Non-Working Xamarin.iOS app.
Comment 4 Sebastien Pouliot 2013-10-23 21:11:21 UTC
That's because when "Dont link" is used nothing gets removed from monotouch.dll

Since nothing gets removed this force us to (native) link (or weak link) every Apple frameworks.

When the (managed) linker is enabled we only (natively) link the required framework.

So what happens is that it's possible some additional libraries (e.g. `libiMagRead.a`) requires some frameworks (that the rest of the application does not need). In this case you need to state which frameworks are required (e.g. in the [LinkWith] attribute or in the "Additional mtouch arguments").

Based on the above errors from `ld` (the native linker) it's looking for:

* AVFoundation (the types that starts with AV*)
* MediaPlayer (the types that starts with MP*)

A quick way to confirm this is to add 

   -gcc_flags="-framework AVFoundation -framework MediaPlayer"

to the "Additional mtouch arguments"
Comment 5 Sebastien Pouliot 2013-10-23 21:13:52 UTC
Created attachment 5224 [details]
Screenshot of Xcode

Look at the list of frameworks that Xcode requires to build the project. If they were absent you'll get the same (or more) errors.
Comment 6 Sebastien Pouliot 2013-10-23 21:20:06 UTC
Compare this to the current [LinkWith] attribute:

[assembly: LinkWith ("libiMagRead.a", LinkTarget = LinkTarget.ArmV7 | LinkTarget.ArmV7s, Frameworks = "AudioToolbox CoreAudio Foundation", ForceLoad = true)]

Now if I add the 2 frameworks from comment #4

[assembly: LinkWith ("libiMagRead.a", LinkTarget = LinkTarget.ArmV7 | LinkTarget.ArmV7s, Frameworks = "AudioToolbox CoreAudio Foundation AVFoundation MediaPlayer", ForceLoad = true)]

the application builds fine (once the bindings are re-built). 

note: this means the Xcode project might be linking extra, non-required, frameworks