From b068f28c48cb6cd7246dcfeaff648327decb3101 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 18 Aug 2017 21:45:21 +0800 Subject: add rpath for macho --- xmake/modules/core/tools/gcc.lua | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'xmake/modules/core/tools/gcc.lua') diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index 96413b718..ddfc264cc 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -234,9 +234,12 @@ end -- make the rpathdir flag function nf_rpathdir(self, dir) - local flag = "-Wl,-rpath=" .. dir - if self:has_flags(flag) then - return flag + local flag_elf = "-Wl,-rpath=" .. dir + local flag_macho = "-Xlinker -rpath -Xlinker " .. dir + if self:has_flags(flag_elf) then + return flag_elf + elseif self:has_flags(flag_macho) then + return flag_macho end end @@ -274,6 +277,12 @@ end -- make the link arguments list function linkargv(self, objectfiles, targetkind, targetfile, flags) + + -- add rpath for dylib (macho), .e.g -install_name @rpath/file.dylib + if targetkind == "shared" and targetfile:endswith(".dylib") then + table.insert(flags, "-install_name") + table.insert(flags, "@rpath/" .. path.filename(targetfile)) + end return self:program(), table.join("-o", targetfile, objectfiles, flags) end -- cgit v1.3.1