Skip to content

Commit

Permalink
[mtouch] -lsqlite3 is a linker flag, not a file to be linked with, so…
Browse files Browse the repository at this point in the history
… treat it accordingly. Fixes #49220. (#1317)

-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
  • Loading branch information
rolfbjarne committed Dec 8, 2016
1 parent e9abb38 commit 7a60602
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
28 changes: 28 additions & 0 deletions tests/mtouch/MTouch.cs
Expand Up @@ -2085,6 +2085,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 = "")
{
Expand Down
12 changes: 6 additions & 6 deletions tools/common/Assembly.cs
Expand Up @@ -370,16 +370,16 @@ public void ComputeLinkerFlags ()
case "libsystem_kernel":
break;
case "sqlite3":
if (LinkWith == null)
LinkWith = new List<string> ();
LinkWith.Add ("-lsqlite3");
if (LinkerFlags == null)
LinkerFlags = new List<string> ();
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<string> ();
LinkWith.Add ("-l" + file.Substring (3));
if (LinkerFlags == null)
LinkerFlags = new List<string> ();
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":
Expand Down

0 comments on commit 7a60602

Please sign in to comment.