From 2daee20867b167699cdcb6b16b95050d709c2b38 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 8 Dec 2016 13:18:58 +0100 Subject: [PATCH] [mtouch] -lsqlite3 is a linker flag, not a file to be linked with, so treat it accordingly. Fixes #49220. -lsqlite3 is a linker flag, not a file to be linked with, so when automatically determining that we need to pass -lsqlite3 we need to put it in the right list of linker information. Otherwise we may end up passing `-force_load -lsqlite3` to the linker (if the assembly's ForceLoad flag is set), which won't compile. https://bugzilla.xamarin.com/show_bug.cgi?id=49220 --- tests/mtouch/MTouch.cs | 28 ++++++++++++++++++++++++++++ tools/common/Assembly.cs | 12 ++++++------ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/tests/mtouch/MTouch.cs b/tests/mtouch/MTouch.cs index b91b15078090..05c2a56202f6 100644 --- a/tests/mtouch/MTouch.cs +++ b/tests/mtouch/MTouch.cs @@ -2172,6 +2172,34 @@ public void MT2015 () } } + [Test] + public void AutoLinkWithSqlite () + { + using (var mtouch = new MTouchTool ()) { + mtouch.Profile = Profile.iOS; + mtouch.CreateTemporaryApp (code: @" +using System.Runtime.InteropServices; +using Foundation; +using ObjCRuntime; + +[assembly: LinkWith (ForceLoad = true)] + +[Preserve (AllMembers = true)] +public class TestApp { + [DllImport (""sqlite3"")] + static extern void sqlite3_exec (); + + static void Main () + { + System.Console.WriteLine (typeof (ObjCRuntime.Runtime).ToString ()); + } +} +"); + mtouch.Linker = MTouchLinker.DontLink; // just to make the test run faster. + mtouch.AssertExecute (MTouchAction.BuildSim, "build"); + } + } + #region Helper functions static string CompileUnifiedTestAppExecutable (string targetDirectory, string code = null, string extraArg = "") { diff --git a/tools/common/Assembly.cs b/tools/common/Assembly.cs index 1cc10d2fc5d2..715adaa43510 100644 --- a/tools/common/Assembly.cs +++ b/tools/common/Assembly.cs @@ -334,16 +334,16 @@ public void ComputeLinkerFlags () case "libsystem_kernel": break; case "sqlite3": - if (LinkWith == null) - LinkWith = new List (); - LinkWith.Add ("-lsqlite3"); + if (LinkerFlags == null) + LinkerFlags = new List (); + LinkerFlags.Add ("-lsqlite3"); Driver.Log (3, "Linking with {0} because it's referenced by a module reference in {1}", file, FileName); break; case "libsqlite3": // remove lib prefix - if (LinkWith == null) - LinkWith = new List (); - LinkWith.Add ("-l" + file.Substring (3)); + if (LinkerFlags == null) + LinkerFlags = new List (); + LinkerFlags.Add ("-l" + file.Substring (3)); Driver.Log (3, "Linking with {0} because it's referenced by a module reference in {1}", file, FileName); break; case "libGLES":