Skip to content

Commit

Permalink
improve rpath for clang linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthapz committed Mar 7, 2024
1 parent a6b26e0 commit b4c3a3e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions xmake/modules/core/tools/clang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,19 @@ function nf_runtime(self, runtime, opt)
-- add rpath to avoid the user need to set LD_LIBRARY_PATH by hand
local rpath_flags
if self:has_flags("-Wl,-rpath=" .. libdir, "ldflags") then
rpath_flags = {"-Wl,-rpath=" .. libdir}
rpath_flags = {"-Wl,-rpath=" .. (libdir:gsub("@[%w_]+", function (name)
local maps = {["@loader_path"] = "$ORIGIN", ["@executable_path"] = "$ORIGIN"}
return maps[name]
end))}
if triple_libdir then
table.join2(rpath_flags, "-Wl,-rpath=" .. triple_libdir)
table.join2(rpath_flags, "-Wl,-rpath=" .. (triple_libdir:gsub("@[%w_]+", function (name)
local maps = {["@loader_path"] = "$ORIGIN", ["@executable_path"] = "$ORIGIN"}
return maps[name]
end)))
end
if self:is_plat("bsd") then
-- FreeBSD ld must have "-zorigin" with "-rpath". Otherwise, $ORIGIN is not translated and it is literal.
table.insert(rpath_flags, 1, "-Wl,-zorigin")
end
elseif self:has_flags("-Xlinker -rpath -Xlinker " .. libdir, "ldflags") then
rpath_flags = {"-Xlinker", "-rpath", "-Xlinker", (libdir:gsub("%$ORIGIN", "@loader_path"))}
Expand Down

0 comments on commit b4c3a3e

Please sign in to comment.