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...
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 6.4.4
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-10-23 20:53 UTC by Jon Goldberger [MSFT]
Modified: 2013-10-23 21:20 UTC (History)
2 users (show)

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


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


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:
Status:
RESOLVED FIXED

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.

THIS IS A MAKE OR BREAK FUNCTIONALITY FOR OUR COMPANY, SEE IF YOU CAN
HELP.. OR WE HAVE FALL BACK TO XCODE :(

Compiling interface definitions
/Applications/Xcode.app/Contents/Developer/usr/bin/ibtool --errors
--warnings --notices --output-format human-readable-text --compile
"/Users/saurabhverma/Projects/TestCard/TestCard/bin/iPhone/Release/TestCard.app/TestCardViewController.nib"
"/Users/saurabhverma/Projects/TestCard/TestCard/TestCardViewController.xib"
--sdk
"/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk"
2013-10-20 00:50:21.175 Interface Builder Cocoa Touch Tool[18794:303]
CFPreferences: user home directory at
file:///Users/saurabhverma/Library/Application%20Support/iPhone%20Simulator/User/
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
"/Users/saurabhverma/Projects/TestCard/TestCard/obj/iPhone/Release/mtouch-cache"
--nomanifest --nosign -dev
"/Users/saurabhverma/Projects/TestCard/TestCard/bin/iPhone/Release/TestCard.app"
-r
"/Users/saurabhverma/Projects/TestCard/MagReadBindings/bin/Release/MagReadBindings.dll"
-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
"/Users/saurabhverma/Projects/TestCard/TestCard/bin/iPhone/Release/TestCard.exe"
Xamarin.iOS 7.0.2 Business Edition using framework:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk
warning MT3005: The dependency 'mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' of the assembly 'MagReadBindings,
Version=0.0.0.0, 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:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
-Wl,-pie -miphoneos-version-min=7.0 -arch armv7 -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk
/Users/saurabhverma/Projects/TestCard/TestCard/obj/iPhone/Release/mtouch-cache/TestCard.exe.armv7.o
/Users/saurabhverma/Projects/TestCard/TestCard/obj/iPhone/Release/mtouch-cache/monotouch.dll.armv7.o
/Users/saurabhverma/Projects/TestCard/TestCard/obj/iPhone/Release/mtouch-cache/mscorlib.dll.armv7.o
/Users/saurabhverma/Projects/TestCard/TestCard/obj/iPhone/Release/mtouch-cache/System.dll.armv7.o
/Users/saurabhverma/Projects/TestCard/TestCard/obj/iPhone/Release/mtouch-cache/MagReadBindings.dll.armv7.o
/Users/saurabhverma/Projects/TestCard/TestCard/obj/iPhone/Release/mtouch-cache/registrar.armv7.o
/Users/saurabhverma/Projects/TestCard/TestCard/obj/iPhone/Release/mtouch-cache/main.armv7.o
-force_load
/Users/saurabhverma/Projects/TestCard/TestCard/obj/iPhone/Release/mtouch-cache/libiMagRead.a
-o
/Users/saurabhverma/Projects/TestCard/TestCard/bin/iPhone/Release/TestCard.app/TestCard
-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
_monotouch_log
/Developer/MonoTouch/SDKs/MonoTouch.iphoneos.sdk/usr/lib/libmonoboehm-2.0.a
/Developer/MonoTouch/SDKs/MonoTouch.iphoneos.sdk/usr/lib/libmonotouch.a
Undefined symbols for architecture armv7:
"_AVAudioSessionCategoryPlayAndRecord", referenced from:
-[AudioHelper checkAndPrepareCategoryForRecording] in
libiMagRead.a(audioHelper.o)
-[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
invocation)

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