summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwsw0108 <[email protected]>2023-10-27 10:13:06 +0800
committerwsw0108 <[email protected]>2023-10-27 10:13:06 +0800
commit985b2a9d54df1ac40a420dc853a7b35cd5e6e377 (patch)
tree3a3790517ddb5947228df0557c96245d304050e0
parent30b0405058c7a90ec60f36179993c74b59717994 (diff)
add @rpath to link flags when soname enabled
-rw-r--r--xmake/modules/core/tools/gcc.lua13
-rw-r--r--xmake/rules/linker/soname/xmake.lua4
2 files changed, 13 insertions, 4 deletions
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index 6589b6f13..4f6eb903f 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -488,8 +488,17 @@ function linkargv(self, objectfiles, targetkind, targetfile, flags, opt)
-- add rpath for dylib (macho), e.g. -install_name @rpath/file.dylib
local flags_extra = {}
if targetkind == "shared" and self:is_plat("macosx", "iphoneos", "watchos") then
- table.insert(flags_extra, "-install_name")
- table.insert(flags_extra, "@rpath/" .. path.filename(targetfile))
+ local soname_enabled = false
+ for _, v in pairs(flags) do
+ if string.find(v, "-install_name") then
+ soname_enabled = true
+ break
+ end
+ end
+ if not soname_enabled then
+ table.insert(flags_extra, "-install_name")
+ table.insert(flags_extra, "@rpath/" .. path.filename(targetfile))
+ end
end
-- add `-Wl,--out-implib,outputdir/libxxx.a` for xxx.dll on mingw/gcc
diff --git a/xmake/rules/linker/soname/xmake.lua b/xmake/rules/linker/soname/xmake.lua
index 8bb160b64..34179f858 100644
--- a/xmake/rules/linker/soname/xmake.lua
+++ b/xmake/rules/linker/soname/xmake.lua
@@ -24,9 +24,9 @@ rule("linker.soname")
if target:is_shared() and soname then
if target:has_tool("sh", "gcc", "gxx", "clang", "clangxx") then
if target:is_plat("macosx", "iphoneos", "watchos", "appletvos") then
- target:add("shflags", "-Wl,-install_name," .. soname, {force = true})
+ target:add("shflags", "-Wl,-install_name,@rpath/" .. soname, {force = true})
else
- target:add("shflags", "-Wl,-soname," .. soname, {force = true})
+ target:add("shflags", "-Wl,-soname,@rpath/" .. soname, {force = true})
end
target:data_set("soname.enabled", true)
end