How to get C# 4.0 in Mono (in xbuild)? - c#-4.0

I have a .NET project which uses msbuild that I want to try building in Mono. I can build some of its trivial targets just fine, but if I try the full compilation it fails.
I'm not sure how much of the output is relevant, but these are the first lines that look like trouble:
Target GetFrameworkPaths:
/usr/lib/mono/3.5/Microsoft.Common.targets: warning : TargetFrameworkVersion 'v4.0' not supported by this toolset (ToolsVersion: 4.0).
and
Target ResolveAssemblyReferences:
/usr/lib/mono/3.5/Microsoft.Common.targets: warning : Reference 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' not resolved
and
/usr/lib/mono/3.5/Microsoft.CSharp.targets: error : Error executing tool '/usr/bin/dmcs': ApplicationName='/usr/bin/dmcs', CommandLine='/noconfig #/tmp/tmp4749932e.tmp', CurrentDirectory='/home/ken/foo/bar'
Task "Csc" execution -- FAILED
I'm running latest Debian unstable. According to this, "dmcs" is the 4.0 compiler. I've not used Mono/xbuild much at all -- is there something special it needs in order to compile a C# 4.0 project? Thanks!

Sid still has Mono 2.6, you probably need Mono 2.10 (available in experimental).

Related

How to fix: "ABI filter 'arm64-v8a' is no longer supported in NDK version x"

I'm setting up an android project from another company which involves selfmade C++ cross platform libraries. For an older version of these libraries an complete app project was made in java with a jni interface to access these libraries, which are stored as their own modules with gradle.build files. The goal is to get the app compiling for arm64-v8a architecture because of the Google requirements for app update.
The project is set up with:
gradle experimental plugin 0.11.0
gradle plugin 4.1
boost 1.64.0 for armeabi-v7a (got arm64-v8a precompiled libraries as replacement)
opencv 2.4.13.2
ndk r15c
I checked all dependencies for getting a arm64 pendant, which was only needed for the boost dependencies.
I tried changing the ABI list which is used for every project to include all architectures or all seperatly. I tried using other ndk versions. What might help but i didn't accomplish was changing the experimental gradle plugin to the normal plugin but i couldn't get that right.
I expected some compiling or linking errors but it only tells me "ABI filter 'arm64-v8a' is no longer supported in NDK version r15.2.4203891.". If i try other architectures i get the same error, but instead of the 'arm64-v8a' the current selected architecture. If i give an invalid architecture it changes to "Target ABI 'hello' is not supported.", so it recognizes the architecture i think.
Stacktrace of first error:
A problem occurred configuring project ':app'.
Exception thrown while executing model rule: NdkComponentModelPlugin.Rules#configureNativeLibrary(ModelMap, NdkConfig, NdkHandler, ModelMap, File, ServiceRegistry) > create(livestage) > withType()
Exception thrown while executing model rule: NdkComponentModelPlugin.Rules#configureNativeLibrary(ModelMap, NdkConfig, NdkHandler, ModelMap, File, ServiceRegistry) > create(lib-jni-cxx) > withType()
Exception thrown while executing model rule: NdkComponentModelPlugin.Rules#configureNativeBinary(BinaryContainer, ModelMap, NdkConfig, NdkHandler) > withType()
ABI filter 'arm64-v8a' is no longer supported in NDK version r15.2.4203891.
The experimental plugin hasn't been supported for years, so it's no surprise that it doesn't work. Migrate to externalNativeBuild: https://developer.android.com/studio/projects/add-native-code

Monotouch Facebook Binding - "make" results in errors

I'm trying to create the Facebook DLL with following bindings: https://github.com/mono/monotouch-bindings/tree/master/facebook
When I use "make", I'm getting following errors:
error: invalid deployment target '5.0.0' for architecture 'arm64' (requires
'7.0.0' or later)
And
** BUILD FAILED **
The following build commands failed: ProcessPCH
/var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/C/com.apple.DeveloperTools/5.0-5A1413/Xcode/SharedPrecompiledHeaders/facebook_ios_sdk_Prefix-eeghlwplbbpvmudycetfsuytcqmf/facebook_ios_sdk_Prefix.pch.pch
facebook_ios_sdk_Prefix.pch normal arm64 objective-c
com.apple.compilers.llvm.clang.1_0.compiler (1 failure) make[1]: *
[libFacebook-arm64.a] Error 65 make: * [build-binding] Error 2
Any ideas?
Ok, finally found the answer myself and posting it here in case others have the same problem.
The make file downloads the Facebook Obj C project automatically
The "BASE SDK" of this project is set to iOS7, the 64bit deployment targets are also set to iOS7, the 32bit deployment targets are set to iOS5
It then builds the Monotouch DLL with the binding project
This targets 64bit, which is not supported on iOS5
So basically, the "make" will not work. You first need to change all deployments targets in the project to iOS7. See screenshot below.
Probably there is a better solution that also supports earlier versions then iOS7, because the Obj C project is using different targets for 32bit (iOS5) and 64bit (iOS7) and my solution now only targets iOS7.

Monotouch - Failed to resolve ExtensionAttribute

Using Xcode 5.0.1 with Xamarin studio Version 4.0.13 (build 38) and Xamarin.iOS
Version: 6.2.4.2
I am getting this error when trying to compile my project:
error MT2002: Failed to resolve "System.Void System.Runtime.CompilerServices.ExtensionAttribute::.ctor()" reference from "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
How can I solve it?
The reason for this error is that between .NET 2.0 (including Silverlight) and 4.0 the [Extension] attribute moved from System.Core.dll to mscorlib.dll.
Xamarin.iOS 6.2 (and earlier) were based on a superset of Silverlight (aka the 2.1 profile). So the [Extension] attribute was located in System.Core.dll.
Since Xamarin.iOS 6.3+ the product was re-based on Mono 3.0 and the profile was updated to use the newer 4.0/4.5 profile. Now the [Extension] attribute is located in mscorlib.dll.
In your case you had a binary assembly compiled against the newer (4.0) profile. That assembly had a reference to mscorlib, Version=4.0.0.0, ... to find [Extension] and would lead to errors if built against the older Xamarin.iOS (6.2 and earlier).
As you found out the easy solution was to update to the latest Xamarin.iOS release. Another way to solve this (without updating Xamarin.iOS) would have been to rebuild (if you have the source) the binary assemblies of your project against the assemblies (BCL) shipped with Xamarin.iOS 6.2.

Undefined "___divmodsi4" linking Monotouch project with static library in release mode

I have a Monotouch project linked to a static library containing C++ modules.
Monotouch version: 3.0.3.5
XCode version: 4.4.1
C/C++ Compiler: Apple LLVM 4.0
When building the project in debug mode for iOS simulator and iOS device everything is OK -
application is linked and runs.
However when building the release configuration for iOS device the following error appears:
Undefined symbols for architecture armv7: "___divmodsi4"
The following line from the static library code somehow causes the trouble:
int number_of_buckets = num_samples / window_samples_step;
If this line is modified as follows the problem disappears:
int number_of_buckets = (int)((float)num_samples / (float)window_samples_step);
Do you have any ideas how to fix the problem without the above modification?
Thanks,
Ury.
This occurs near the end of the build and generally depends on it's original parameters. Try to compare your options between your Release and Debug builds and check that:
you are using the same Additional mtouch arguments on both configuration;
you are using the same compiler, Mono AOT versus LLVM compilers, on both configuration;
you are using the same architecture, ARMv6 versus ARMv7, on both configuration.
Otherwise attach (e.g. preferable to a bug report or pastebin) the full build log (from the Build Output of MonoDevelop's Error Pad) for both Debug and Release builds.
To be more helpful add "-v -v -v" to the Additional mtouch arguments before re-building. This will augment the verbosity (details) about each steps.
You need to set the app's Deployment Target (in the project's options, Build / iPhone Application page) to at least 5.0.

ServiceStack Monotouch iPhone/Release Build Fails

UPDATE - This indeed fails only in release builds, but only when the LLVM compiler option is used. Creating a self-contained test case for Xamarin that I'll post as the answer.
I have a project which uses the ServiceStack.Common.Monotouch.dll, ServiceStack.Interfaces.Monotouch.dll, and ServiceStack.Text.Monotouch.dll. I can build this project in Simulator/Release & Debug, and iPhone/Debug, but when I build in iPhone/Release, I get the following error:
...
MONO_PATH=/Users/pseabury/Projects/IMDSS_iOS/IMDSSMobile_iOS/bin/iPhone/Release/IMDSSMobile_iOS.app /Developer/MonoTouch/usr/bin/arm-darwin-mono --llvm --aot=mtriple=armv7-darwin,full,static,asmonly,nodebug,llvm-path=/Developer/MonoTouch/LLVM/bin/,outfile=/var/folders/mt/b7h3_pgs3lxgpvpm2h1_2ppc0000gn/T/tmp39b8b8c7.tmp/System.Data.dll.7.s "/Users/pseabury/Projects/IMDSS_iOS/IMDSSMobile_iOS/bin/iPhone/Release/IMDSSMobile_iOS.app/System.Data.dll"
AOT Compilation exited with code 134, command:
MONO_PATH=/Users/pseabury/Projects/IMDSS_iOS/IMDSSMobile_iOS/bin/iPhone/Release/IMDSSMobile_iOS.app /Developer/MonoTouch/usr/bin/arm-darwin-mono --llvm --aot=mtriple=armv7-darwin,full,static,asmonly,nodebug,llvm-path=/Developer/MonoTouch/LLVM/bin/,outfile=/var/folders/mt/b7h3_pgs3lxgpvpm2h1_2ppc0000gn/T/tmp39b8b8c7.tmp/ServiceStack.Text.MonoTouch.dll.7.s "/Users/pseabury/Projects/IMDSS_iOS/IMDSSMobile_iOS/bin/iPhone/Release/IMDSSMobile_iOS.app/ServiceStack.Text.MonoTouch.dll"
Mono Ahead of Time compiler - compiling assembly /Users/pseabury/Projects/IMDSS_iOS/IMDSSMobile_iOS/bin/iPhone/Release/IMDSSMobile_iOS.app/ServiceStack.Text.MonoTouch.dll
* Assertion at ../../../../../mono/mono/mini/mini-llvm.c:4535, condition `LLVMTypeOf (values [sreg1]) == LLVMTypeOf (values [phi->dreg])' not met
...
mtouch exited with code 1
If necessary I can put together an example project, but all you should need is the latest ServiceStack dlls or sources for Monotouch and a sample/contrived DTO for a ServiceClient in order to reproduce this.
Bug submitted to Xamarin - https://bugzilla.xamarin.com/show_bug.cgi?id=6066 .

Resources