From 51cda3b468b399107459bb63e35221bd5eb89367 Mon Sep 17 00:00:00 2001 From: Marius Ungureanu Date: Fri, 2 Jun 2017 00:19:04 -0700 Subject: [PATCH] [Mac,iOS] Generate create_classes as C methods so they can be used from objc. (#2158) This change introduces the export of create_classes methods as objc compatible, without enforcing Objective-C++ as the development language for custom registrar embedders by moving the stringbuilder flushing inside the extern "C" block. Mark the generated linking code as extern "C" too and also change the return type of xamarin_create_classes_Xamarin_Mac to void in mmp generation, as it was mistakenly set to int. --- tools/common/StaticRegistrar.cs | 11 ++++++----- tools/mmp/driver.cs | 2 +- tools/mtouch/mtouch.cs | 2 +- tools/mtouch/simlauncher.m | 8 ++++++++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/tools/common/StaticRegistrar.cs b/tools/common/StaticRegistrar.cs index bd11c4e6cf..53c96c97e2 100644 --- a/tools/common/StaticRegistrar.cs +++ b/tools/common/StaticRegistrar.cs @@ -3803,20 +3803,21 @@ namespace XamCore.Registrar { Specialize (sb); + methods.WriteLine (); + methods.AppendLine (); + methods.AppendLine (sb); + methods.StringBuilder.AppendLine ("} /* extern \"C\" */"); FlushTrace (); + Driver.WriteIfDifferent (source_path, methods.ToString ()); + header.AppendLine (); header.AppendLine (declarations); header.AppendLine (interfaces); Driver.WriteIfDifferent (header_path, header.ToString ()); - methods.WriteLine (); - methods.AppendLine (); - methods.AppendLine (sb); - Driver.WriteIfDifferent (source_path, methods.ToString ()); - header.Dispose (); header = null; declarations.Dispose (); diff --git a/tools/mmp/driver.cs b/tools/mmp/driver.cs index fd95ff83fd..ff61c6b067 100644 --- a/tools/mmp/driver.cs +++ b/tools/mmp/driver.cs @@ -1113,7 +1113,7 @@ namespace Xamarin.Bundler { sw.WriteLine ("#import "); sw.WriteLine ("#import "); // 10.7 wants this even if not needed on 10.9 if (Driver.registrar == RegistrarMode.PartialStatic) - sw.WriteLine ("extern int xamarin_create_classes_Xamarin_Mac ();"); + sw.WriteLine ("extern \"C\" void xamarin_create_classes_Xamarin_Mac ();"); sw.WriteLine (); sw.WriteLine (); sw.WriteLine (); diff --git a/tools/mtouch/mtouch.cs b/tools/mtouch/mtouch.cs index f980f97c24..7561824e5b 100644 --- a/tools/mtouch/mtouch.cs +++ b/tools/mtouch/mtouch.cs @@ -615,7 +615,7 @@ namespace Xamarin.Bundler if (registration_methods != null) { foreach (var method in registration_methods) { - sw.Write ("void "); + sw.Write ("extern \"C\" void "); sw.Write (method); sw.WriteLine ("();"); } diff --git a/tools/mtouch/simlauncher.m b/tools/mtouch/simlauncher.m index 229f8099e9..03a4c819a4 100644 --- a/tools/mtouch/simlauncher.m +++ b/tools/mtouch/simlauncher.m @@ -9,8 +9,16 @@ #include "xamarin/xamarin.h" +#ifdef __cplusplus +extern "C" { +#endif + void xamarin_create_classes_Xamarin_iOS (); +#ifdef __cplusplus +} +#endif + void xamarin_setup_impl () { #if DEBUG