From e8e727d68189d699c6cab22079032e0c5bdd2aa7 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Mon, 4 Dec 2017 11:34:37 +0200 Subject: [PATCH] Fix linking to LLVM libs on linux, when system has llvm/clang installed. (#1020) This change prevents premake from inserting /usr/lib64 search path on linux. GCC does not need this path specified compiler automatically knows where to look for system libs. Insertion of this path causes issues system has clang/llvm libs installed. Build would link to system libraries instead of custom required by CppSharp. Also this patch revealed that linking to `pthread`, `z` and `tinfo` libraries on linux is not necessary and disabling them in LLVM build config works. Linking to these libs was removed. As you probably have guessed in the past CppSharp would throw `DllNotFoundException` due to missing symbols because it linked to system LLVM libs, not custom in-tree LLVM build. --- build/LLVM.lua | 9 +-------- build/scripts/LLVM.lua | 8 ++++++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/build/LLVM.lua b/build/LLVM.lua index 507fcbad..225bcec5 100644 --- a/build/LLVM.lua +++ b/build/LLVM.lua @@ -100,20 +100,13 @@ function SetupLLVMLibs() defines { "__STDC_CONSTANT_MACROS", "__STDC_LIMIT_MACROS" } filter { "system:macosx" } - links { "c++", "curses" } - - filter { "system:macosx or system:linux" } - links { "pthread", "z" } + links { "c++", "curses", "pthread", "z" } filter { "action:vs*" } links { "version" } filter {} - if os.ishost("linux") and os.isfile("/usr/lib/libtinfo.so") then - links { "tinfo" } - end - if LLVMDirPerConfiguration then filter { "configurations:Debug" } libdirs { path.join(LLVMRootDirDebug, "build/lib") } diff --git a/build/scripts/LLVM.lua b/build/scripts/LLVM.lua index d40c420f..7f60395d 100644 --- a/build/scripts/LLVM.lua +++ b/build/scripts/LLVM.lua @@ -4,6 +4,14 @@ require "../Helpers" local llvm = path.getabsolute(basedir .. "/../deps/llvm") +-- Prevent premake from inserting /usr/lib64 search path on linux. GCC does not need this path specified +-- as compiler automatically knows where to look for system libs. Insertion of this path causes issues +-- when system has clang/llvm libs installed. Build would link to system libraries instead of custom +-- build required by CppSharp. +if os.istarget("linux") then + premake.tools.gcc.libraryDirectories['architecture']['x86_64'] = function(cfg) return {} end +end + -- If we are inside vagrant then clone and build LLVM outside the shared folder, -- otherwise file I/O performance will be terrible. if is_vagrant() then