Bug 22906 - Linking native library with mtouch: ${ProjectDir} resolve to Windows instead of Host (since Xamarin 3.5)
Summary: Linking native library with mtouch: ${ProjectDir} resolve to Windows instead ...
Status: VERIFIED FIXED
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: iOS ()
Version: 3.5
Hardware: PC Windows
: High major
Target Milestone: 15.4
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-09-12 03:57 UTC by Virgile Bello
Modified: 2018-04-25 09:02 UTC (History)
13 users (show)

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

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 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:
VERIFIED FIXED

Description Virgile Bello 2014-09-12 03:57:25 UTC
If I create a project with following additional mtouch arguments:
-gcc_flags "-L${ProjectDir} -lXXX -force_load ${ProjectDir}/source/libXXX.a"

It used to work until Xamarin 3.3.
However, since upgrading to Xamarin 3.5, it doesn't work.

It seems that ${ProjectDir} resolves to windows path (C:/Users/USERNAME/Documents/Visual Studio 2012/Projects/OpenGL7/source/libbulletc.a) instead of MacOSX host path (/Users/USERNAME/Library/Caches/Xamarin/mtbs/builds/OpenGL7/b48b119bc3eab24b14e0a1112c72237a/obj/iPhone/Debug/mtouch-cache/...).

1>  Tool /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch execution started with arguments: --cache obj/iPhone/Debug/mtouch-cache --nomanifest --nosign --dev bin/iPhone/Debug/OpenGL7.app --debug --linksdkonly --sdkroot /Applications/Xcode.app/Contents/Developer --sdk 7.1 --targetver 5.0 --abi=armv7 --gcc_flags "\"-LC:/Users/USERNAME/Documents/Visual Studio 2012/Projects/OpenGL7\" -lbulletc -force_load \"C:/Users/USERNAME/Documents/Visual Studio 2012/Projects/OpenGL7/source/libbulletc.a\"" -r bin/iPhone/Debug/monotouch.dll -r bin/iPhone/Debug/mscorlib.dll -r bin/iPhone/Debug/OpenTK-1.0.dll -r bin/iPhone/Debug/PortableClassLibrary1.dll -r bin/iPhone/Debug/System.Core.dll -r bin/iPhone/Debug/System.dll -r bin/iPhone/Debug/System.Xml.dll bin/iPhone/Debug/OpenGL7.exe  (TaskId:55)
1>  Xamarin.iOS 8.0.0 Business Edition using framework: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk (TaskId:55)
1>  Process exited with code 1, command: (TaskId:55)
1>  /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang  -Wl,-pie  -arch armv7 -miphoneos-version-min=5.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk /Users/USERNAME/Library/Caches/Xamarin/mtbs/builds/OpenGL7/b48b119bc3eab24b14e0a1112c72237a/obj/iPhone/Debug/mtouch-cache/OpenGL7.exe.armv7.o /Users/USERNAME/Library/Caches/Xamarin/mtbs/builds/OpenGL7/b48b119bc3eab24b14e0a1112c72237a/obj/iPhone/Debug/mtouch-cache/mscorlib.dll.armv7.o /Users/USERNAME/Library/Caches/Xamarin/mtbs/builds/OpenGL7/b48b119bc3eab24b14e0a1112c72237a/obj/iPhone/Debug/mtouch-cache/monotouch.dll.armv7.o /Users/USERNAME/Library/Caches/Xamarin/mtbs/builds/OpenGL7/b48b119bc3eab24b14e0a1112c72237a/obj/iPhone/Debug/mtouch-cache/System.dll.armv7.o /Users/USERNAME/Library/Caches/Xamarin/mtbs/builds/OpenGL7/b48b119bc3eab24b14e0a1112c72237a/obj/iPhone/Debug/mtouch-cache/OpenTK-1.0.dll.armv7.o /Users/USERNAME/Library/Caches/Xamarin/mtbs/builds/OpenGL7/b48b119bc3eab24b14e0a1112c72237a/obj/iPhone/Debug/mtouch-cache/registrar.armv7.o /Users/USERNAME/Library/Caches/Xamarin/mtbs/builds/OpenGL7/b48b119bc3eab24b14e0a1112c72237a/obj/iPhone/Debug/mtouch-cache/main.armv7.o -o bin/iPhone/Debug/OpenGL7.app/OpenGL7 -framework QuartzCore -framework CoreGraphics -framework Foundation -framework CoreVideo -framework OpenGLES -framework UIKit -framework CFNetwork -lz -liconv -u _mono_pmip -u _monotouch_log -u _monotouch_release_managed_ref -u _monotouch_create_managed_ref -u _xamarin_get_block_descriptor /Library/Frameworks/Xamarin.iOS.framework/Versions/8.0.0.9/SDKs/MonoTouch.iphoneos.sdk/usr/lib/libmonoboehm-2.0.a /Library/Frameworks/Xamarin.iOS.framework/Versions/8.0.0.9/SDKs/MonoTouch.iphoneos.sdk/usr/lib/libmonotouch-debug.a "-LC:/Users/USERNAME/Documents/Visual Studio 2012/Projects/OpenGL7" -lbulletc -force_load "C:/Users/USERNAME/Documents/Visual Studio 2012/Projects/OpenGL7/source/libbulletc.a" (TaskId:55)
1>  ld: file not found: C:/Users/USERNAME/Documents/Visual Studio 2012/Projects/OpenGL7/source/libbulletc.a (TaskId:55)
1>  clang: error: linker command failed with exit code 1 (use -v to see invocation) (TaskId:55)
1>   (TaskId:55)
1>C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(383,3): error : Native linking error: file not found: C:/Users/USERNAME/Documents/Visual Studio 2012/Projects/OpenGL7/source/libbulletc.a
1>C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(383,3): error : Native linking failed. Please review the build log and the user flags provided to gcc: "-LC:/Users/USERNAME/Documents/Visual Studio 2012/Projects/OpenGL7" -lbulletc -force_load "C:/Users/USERNAME/Documents/Visual Studio 2012/Projects/OpenGL7/source/libbulletc.a"
1>C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(383,3): error : Native linking failed. Please review the build log.
1>  Tool /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch execution finished. (TaskId:55)
Comment 1 Parmendra Kumar 2014-09-12 06:16:44 UTC
I have tried to reproduce this issue and unable to reproduce it. Could you
please provide us the sample project or some steps to reproduce this
issue ?.
Comment 2 Virgile Bello 2014-09-12 07:07:29 UTC
Easy way to reproduce:
1. Create iOS executable app
2. Go in project  build property, mtouch addition arguments
3. Set something like "-test ${ProjectDir}" (this will make it easy to search for in the log after).
4. Build (with Mac host attached so that mtouch executes).
5. Check the build log (both visual studio and MacOS ones) for mtouch command line and check what ProjectDir has been expanded into (search for -test in build log and what's right after it). It should be followed by a MacOS path to work properly, not a Windows path ( I.e. -test /Users/... vs -test C:/projects/...).

Note: Of course mtouch will fail because -test is invalid. But point is to easily show problem with ProjectDir variable not being transformed properly.
Comment 3 Miguel de Icaza [MSFT] 2014-09-12 09:21:01 UTC
Information was provided.
Comment 4 Adrian Alonso 2014-09-12 10:58:13 UTC
We're already working on fixing this but in the meantime if you need a workaround you could fix the ProjectFullPath used by the MTouchTask in the Xamarin.iOS.Common.targets (located at C:\Program Files (x86)\MSBuild\Xamarin\iOS directory) and set the valid directory in the mac:

			ProjectFullPath="/Users/xxx/Library/Caches/Xamarin/mtbs/builds/$(ProjectName)/$(BuildSessionId)/"
Comment 5 Virgile Bello 2014-09-12 12:16:47 UTC
Thanks for the workaround, and happy to know it was already a known issue!

However, since it's a SDK used on top of Xamarin that we distribute, we can't really expect every of our users to do that change.

If I understood right, it is impossible to use any native library right now?
Any ETA on when will this be fixed in Xamarin version shipped to customers?
Comment 7 Virgile Bello 2014-09-16 02:30:18 UTC
As this is part of Xamarin iOS, how can we test with latest master before it is released in v3.7?

Also, how can I know when v3.7 including this change will be released?
Might take a few weeks, right?
Comment 8 Virgile Bello 2014-09-17 07:04:01 UTC
Sorry, reopening just to have a quick answer to latest question.
Thanks!
Comment 10 Virgile Bello 2014-09-19 03:47:24 UTC
Thanks for the clarification!
Comment 11 Mohit Kheterpal 2014-10-01 06:25:03 UTC
I have checked this issue by adding following mtouch argument 

-gcc_flags "-L${ProjectDir} -lXXX -force_load ${ProjectDir}/source/libXXX.a"

with XVS 3.7.188 + X.iOS 8.2.0.187 but I am still getting following error :

mtbs log : https://gist.github.com/Mohit-Kheterpal/e8869f0a8e24cdcc0da3
build error : https://gist.github.com/Mohit-Kheterpal/79b7aa9b8127f6ddb700
macserver log : https://gist.github.com/Mohit-Kheterpal/a24df82aaa24afe57c1f

Hence reopening this issue.

And please let me know if I have to check something else ?

Environment info :
Microsoft Visual Studio Professional 2013
Version 12.0.21005.1 REL
Microsoft .NET Framework
Version 4.5.52742

Installed Version: Professional

Xamarin   3.7.188.0 (830a1477f07719a370cd6f5e905124c0cb2a57c6)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   4.18.0.32 (04399d62cfc00624d575239d1762ea4fd6d012e2)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS   8.2.0.0 (a1f0a7a951a158ce3b9445e387ea737a083ffd79)
Visual Studio extension to enable development for Xamarin.iOS.
Comment 13 Mohit Kheterpal 2014-10-01 12:00:29 UTC
As per comment 12, the reported issue is fixed. Hence closing this issue by marking it as verified.
Comment 14 Virgile Bello 2014-10-05 23:06:39 UTC
FYI, this tutorial still doesn't work:
http://developer.xamarin.com/guides/ios/advanced_topics/native_interop/

To get around the issue, I had to:
1/ Mark native library as BundleResource so that it gets copied to the Mac.
2/ Remove the "source" subdirectory that was previously needed on Visual Studio only (when specifying -L and -force_load).
Comment 15 Virgile Bello 2014-10-05 23:07:31 UTC
Note:
Marking it as Content does work too, but it gets copied in the app bundle.
Marking it as None doesn't work (not copied).
Comment 16 Virgile Bello 2014-10-05 23:12:06 UTC
Never mind, BundleResource also gets it copied inside the app bundle :/
Going to investigate further.
Comment 17 Stas 2015-05-22 04:55:47 UTC
Reopening bug, after updating on Xamarin.iOS 8.10.0 on Windows is started to reproduce

workaround - as in https://bugzilla.xamarin.com/show_bug.cgi?id=22906#c4

but now you should change value of ProjectDir="$(MtouchProjectDirectory)"
Comment 18 Prashant [MSFT] 2017-04-12 10:14:34 UTC
Looks like this issue still exists the Xamarin 4.4.0.34 (3f99c5a) and Xamarin.iOS and Xamarin.Mac SDK   10.8.0.174 (7656cc6)

## Build log https://gist.github.com/prashantvc/ae09398333f133cd3548ed9378f79146#file-buildlog-L4-L5

## Version information

Microsoft Visual Studio Enterprise 2017 
Version 15.1 (26403.0) Release
VisualStudio.15.Release/15.1.0+26403.0
Microsoft .NET Framework
Version 4.7.02046

Installed Version: Enterprise

Architecture Diagrams and Analysis Tools   00369-60000-00001-AA051
Microsoft Architecture Diagrams and Analysis Tools

Visual Basic 2017   00369-60000-00001-AA051
Microsoft Visual Basic 2017

Visual C# 2017   00369-60000-00001-AA051
Microsoft Visual C# 2017

Visual F# 4.1   00369-60000-00001-AA051
Microsoft Visual F# 4.1

Application Insights Tools for Visual Studio Package   8.6.00209.10
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017   15.0.30320.0
ASP.NET and Web Tools 2017

ASP.NET Web Frameworks and Tools 2017   5.2.50303.0
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0   15.0.30209.0
Azure App Service Tools v3.0.0

Azure Data Lake Node   1.0
This package contains the Data Lake integration nodes for Server Explorer.

Azure Data Lake Tools for Visual Studio   2.2.5000.0
Microsoft Azure Data Lake Tools for Visual Studio

Common Azure Tools   1.9
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

JavaScript Language Service   2.0
JavaScript Language Service

KofePackagePackage Extension   1.0
KofePackagePackage Visual Studio Extension Detailed Info

Merq   1.1.17-rc (cba4571)
Command Bus, Event Stream and Async Manager for Visual Studio extensions.

Microsoft Azure Hive Query Language Service   2.2.5000.0
Language service for Hive query

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.50131.1

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Mono Debugging for Visual Studio   Mono.Debugging.VisualStudio
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   4.1.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

SQL Server Data Tools   15.1.61702.140
Microsoft SQL Server Data Tools

ToolWindowHostedEditor   1.0
Hosting json editor into a tool window

TypeScript   2.1.5.0
TypeScript tools for Visual Studio

Xamarin   4.4.0.34 (3f99c5a)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android SDK   7.2.0.7 (b16fb82)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK   10.8.0.174 (7656cc6)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
Comment 19 Adrian Alonso 2017-06-28 20:28:28 UTC
The usage of $(ProjectDir) in the mtouch additional arguments is translated to /Users/{UserName}/Library/Caches/Xamarin/mtbs/builds/{AppName}/{Guid}
Comment 20 Stefan.Wert 2017-07-11 18:57:37 UTC
I am also seeing this issue when trying to build an iOS project from Visual Studio. In my case, the native library is included in a nuget that my iOS project depends on.


## Version information (PC)

Microsoft Visual Studio Professional 2017 
Version 15.2 (26430.13) Release
VisualStudio.15.Release/15.2.0+26430.13
Microsoft .NET Framework
Version 4.6.01038

Installed Version: Professional

Visual Basic 2017   00369-60000-00001-AA946
Microsoft Visual Basic 2017

Visual C# 2017   00369-60000-00001-AA946
Microsoft Visual C# 2017

Visual C++ 2017   00369-60000-00001-AA946
Microsoft Visual C++ 2017

Visual F# 4.1   00369-60000-00001-AA946
Microsoft Visual F# 4.1

ASP.NET and Web Tools 2017   15.0.30503.0
ASP.NET and Web Tools 2017

Azure App Service Tools v3.0.0   15.0.30209.0
Azure App Service Tools v3.0.0

Common Azure Tools   1.9
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Cookiecutter   3.0.17114.1
Provides tools for finding, instantiating and customizing templates in cookiecutter format.

CustomizeVSWindowTitle 3   1.0
Information about my package

GitClientVSPackage Extension   1.0
GitClientVSPackage Visual Studio Extension Detailed Info

JavaScript Language Service   2.0
JavaScript Language Service

JavaScript Project System   2.0
JavaScript Project System

License Header Manager   2.0.0
An extension for automatically inserting license information file headers.

Merq   1.1.17-rc (cba4571)
Command Bus, Event Stream and Async Manager for Visual Studio extensions.

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.50131.1

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

Mono Debugging for Visual Studio   Mono.Debugging.VisualStudio
Support for debugging Mono processes with Visual Studio.

Node.js Tools   1.3.50417.1
Adds support for developing and debugging Node.js apps in Visual Studio

NuGet Package Manager   4.2.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

Python   3.0.17114.1
Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.

Python - Django support   3.0.17114.1
Provides templates and integration for the Django web framework.

Python - IronPython support   3.0.17114.1
Provides templates and integration for IronPython-based projects.

Python - Profiling support   3.0.17114.1
Profiling support for Python projects.

SonarLint for Visual Studio   3.2.1.1639
SonarLint is an extension to your favorite IDE that provides on-the-fly feedback to developers on new bugs and quality issues injected into their code.

Trailing Whitespace Visualizer   2.5.83
Keeps your code files clean by making it easier than ever to identify and remove any trailing whitespace

TypeScript   2.2.2.0
TypeScript tools for Visual Studio

ViEmu for Visual Studio   3.7.6
ViEmu: vi/vim emulation for Microsoft Visual Studio. (c) 2005-2017 Symnum Systems. Please visit http://www.viemu.com for details.

Visual Studio Tools for Unity   3.1.0.0
Visual Studio Tools for Unity

Web Extension Pack 2017   15.0.2
The easiest way to set up Visual Studio for the ultimate web development experience.

Xamarin   4.5.0.486 (fec6f88)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android SDK   7.3.1.2 (9dbc4c5)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK   10.10.0.37 (ad35de4)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

## Version information (Mac)

Visual Studio Community 2017 for Mac
Version 7.0.1 (build 24)
Installation UUID: 34aa3ed2-9f1e-4db0-9e36-daa5725f27a9
Runtime:
	Mono 5.0.1.1 (2017-02/5077205) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 500010001

NuGet
Version: 4.0.0.2323

.NET Core
Runtime: /usr/local/share/dotnet/dotnet
SDK: /usr/local/share/dotnet/sdk/1.0.1/Sdks
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.0.1/lib/mono/msbuild/15.0/bin/Sdks

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

Apple Developer Tools
Xcode 8.3.2 (12175)
Build 8E2002

Xamarin.Android
Version: 7.3.1.2 (Visual Studio Community)
Android SDK: /Users/swert/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.4   (API level 19)
		6.0   (API level 23)

SDK Tools Version: 25.1.2
SDK Platform Tools Version: 24.0.0
SDK Build Tools Version: 23.0.2

Java SDK: /usr
java version "1.8.0_73"
Java(TM) SE Runtime Environment (build 1.8.0_73-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.73-b02, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Xamarin Inspector
Version: 1.2.2
Hash: b71b035
Branch: d15-1
Build date: Fri, 21 Apr 2017 17:57:12 GMT

Xamarin.iOS
Version: 10.10.0.36 (Visual Studio Community)
Hash: d2270eec
Branch: d15-2
Build date: 2017-05-22 16:30:53-0400

Xamarin.Mac
Version: 3.4.0.36 (Visual Studio Community)

Build Information
Release ID: 700010024
Git revision: 7ab1ca2ced6f584e56b7a0d4d321d00775cd95c9
Build date: 2017-05-19 05:44:51-04
Xamarin addins: 08d17158f3365beee5e60f67999e607cce4b3f93
Build lane: monodevelop-lion-d15-2

Operating System
Mac OS X 10.12.5
Darwin 16.6.0 Darwin Kernel Version 16.6.0
    Fri Apr 14 16:21:16 PDT 2017
    root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64

Enabled user installed addins
NuGet Package Management Extensions 0.12.2
Comment 22 mwesolowski 2018-04-25 09:02:56 UTC
Are there any plans to escape ${ProjectDir} when containing spaces?