The problem is that the Unreal Build Tool is using improper ld
parameters. I’ve fixed the issue and submitted a pull request on Github. However, to fix it now you just have to perform two changes.
First, inside Engine/Source/Programs/UnrealBuildTool/Mac/.cs, delete line 751 ( LinkCommand += string.Format(" -l{0}", AdditionalLibrary);
) and paste this code in its place.
EDIT: It’s line 751 in master branch (as seen in the pull request), but it’s line 743 in the version in the release
branch.
EDIT 2: If you look at the code submitted to the pull request, make sure you only copy and paste in the code I’ve changed. If you were to copy the entire .cs file from the master branch, to a release branch install you’ll get compile errors due to other unrelated changes to the file.
//Parse out the components of AdditionalLibrary.
//For a common system library, AdditionalLibrary will be just a name. Ex: AdditionalLibrary = "z" is to include "libz.a".
//However, for a custom library, it may be given as a path to the file. Ex: AdditonalLibrary = "ThirdParty/Source/sqlite/lib/Mac/Debug/libsqlite.a"
string libDirectory = Path.GetDirectoryName(AdditionalLibrary);
string libExtension = Path.GetExtension(AdditionalLibrary);
string libName = Path.GetFileNameWithoutExtension(AdditionalLibrary); //expected output from "/ex/lib/dir/mylib.a" is "mylib"
//Note: All of my comments mention ".a" files, however, this also applies to ".dylib" files.
if(libExtension == ".a" || libExtension == ".dylib"){ //If this is a Mac static/dynamic library , given as a path to a specific file.
if(!libExtension.StartsWith("lib")){
Log.TraceWarning("Static library given as path to file named {0}{1}. Continuing, but `ld -l` will actually be searching for files named lib{0}.a or lib{0}.dylib!", libName, libExtension);
}
else{
libName = libName.Substring(3); //Trim off "lib" prefix from "libmylib.a", as the Mac `ld -lmylib` flag will actually search for "libmylib.a". So, if `ld -llibmylib` was given, it'd search for "liblibmylib.a".
}
//Log.TraceInformation("Using new library format for \"{0}\" (lib{0}.a) in search dir \"{1}\"", libName, libDirectory);
LinkCommand += string.Format(" -L{0}", libDirectory); //Add a new library search path
LinkCommand += string.Format(" -l{0}", libName); //search for the lib by name. Given the value "mylib" ld will search for "libmylib.a" within the added search directory.
}
else{
//Log.TraceInformation("Using old library format for \"{0}\" (lib{0}.a)",AdditionalLibrary);
LinkCommand += string.Format(" -l{0}", AdditionalLibrary); //Leaving this here in the hope that I don't break other functionailty, though accoring to the ld man page, this shouldn't work if AdditionalLibrary is a path to a specific .a file.
}
For the second change, it’s important to note this section from the man ld
page:
-lx This option tells the linker to search for libx.dylib or
libx.a in the library search path. If string x is of the
form y.o, then that file is searched for in the same places,
but without prepending `lib' or appending `.a' or `.dylib' to
the filename.
So, make sure inside ThirdParty/sqlite/lib/Mac/Debug/ and ThirdParty/sqlite/lib/Mac/Release/ you name the sqlite library file libsqlite.a.
You do (edit: I originally thought you didn’t, but you do) need to edit the SQLiteSupport.Build.cs file. You need to change the filename string from “sqlite” to “libsqlite”.