-
-
Notifications
You must be signed in to change notification settings - Fork 399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
在macos下自定义package,自定义toolchain、sdk、ldflags时编译dxc出现链接错误 #4815
Comments
Title: A link error occurs when compiling dxc when customizing the package, toolchain, sdk, and ldflags under macos. |
export LLVM_DIR="/usr/local/opt/llvm";
cmake DirectXShaderCompiler \
-B dxc \
-C DirectXShaderCompiler/cmake/caches/PredefinedParams.cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=$LLVM_DIR/bin/clang \
-DCMAKE_CXX_COMPILER=$LLVM_DIR/bin/clang++ \
-DCMAKE_AR=$LLVM_DIR/bin/llvm-ar \
-DCMAKE_LINKER=$LLVM_DIR/bin/llvm-ld \
-DCMAKE_NM=$LLVM_DIR/bin/llvm-nm \
-DCMAKE_OBJDUMP=$LLVM_DIR/bin/llvm-objdump \
-DCMAKE_RANLIB=$LLVM_DIR/bin/llvm-ranlib \
-DCMAKE_SHARED_LINKER_FLAGS="-L/usr/local/opt/llvm/lib/ -L/usr/local/opt/llvm/lib/c++ -Wl -rpath /usr/local/opt/llvm/lib/c++" \
-DCMAKE_EXE_LINKER_FLAGS="-L/usr/local/opt/llvm/lib/ -L/usr/local/opt/llvm/lib/c++ -Wl -rpath /usr/local/opt/llvm/lib/c++" \
-G "Ninja" 我自行clone工程,使用以上命令是可以编译成功的,感觉就是 |
既然自己本地可以,那你对下最后的 link flags ,看下差异。 |
Since you can do it locally, check the last link flags and see the difference. |
这是xmake调用cmake config生成的ninja命令片段
这个是用上面手敲的cmake命令生成的ninja命令片段
|
破案了,原来ldflags是针对可执行程序,不包括动态库,还要设置shflags 目前xmake版本是 v2.9.6 自定义llvm工具链并设置ldflags和shflags后就可以正常编译了 toolchain("llvm-macos-brew")
set_kind("standalone")
set_homepage("https://llvm.org/")
set_description("A collection of modular and reusable compiler and toolchain technologies")
set_runtimes("c++_static", "c++_shared", "stdc++_static", "stdc++_shared")
set_sdkdir("/usr/local/opt/llvm")
set_toolset("cc", "clang")
set_toolset("cxx", "clang", "clang++")
set_toolset("mxx", "clang", "clang++")
set_toolset("mm", "clang")
set_toolset("cpp", "clang -E")
set_toolset("as", "clang")
set_toolset("ld", "clang++", "clang")
set_toolset("sh", "clang++", "clang")
set_toolset("ar", "llvm-ar")
set_toolset("strip", "llvm-strip")
set_toolset("ranlib", "llvm-ranlib")
set_toolset("objcopy","llvm-objcopy")
set_toolset("mrc", "llvm-rc")
on_load(function (toolchain)
if toolchain:is_plat("macosx") then
local xcode_dir = get_config("xcode")
local xcode_sdkver = toolchain:config("xcode_sdkver")
local xcode_sdkdir = nil
if xcode_dir and xcode_sdkver then
xcode_sdkdir = xcode_dir .. "/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk"
toolchain:add("cxflags", {"-isysroot", xcode_sdkdir})
toolchain:add("mxflags", {"-isysroot", xcode_sdkdir})
toolchain:add("ldflags", {"-isysroot", xcode_sdkdir})
toolchain:add("shflags", {"-isysroot", xcode_sdkdir})
else
local macsdk = "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
if os.exists(macsdk) then
toolchain:add("cxflags", {"-isysroot", macsdk})
toolchain:add("mxflags", {"-isysroot", macsdk})
toolchain:add("ldflags", {"-isysroot", macsdk})
toolchain:add("shflags", {"-isysroot", macsdk})
end
end
toolchain:add("mxflags", "-fobjc-arc")
toolchain:add("ldflags", format("-L%s/lib/", toolchain:sdkdir()))
toolchain:add("ldflags", format("-L%s/lib/c++/", toolchain:sdkdir()))
toolchain:add("ldflags", format("-Wl,-rpath,%s/lib/c++", toolchain:sdkdir()))
toolchain:add("shflags", format("-L%s/lib/", toolchain:sdkdir()))
toolchain:add("shflags", format("-L%s/lib/c++/", toolchain:sdkdir()))
toolchain:add("shflags", format("-Wl,-rpath,%s/lib/c++", toolchain:sdkdir()))
end
end)
toolchain_end()
|
Xmake 版本
v2.9.4
操作系统版本和架构
macOS Monterey 12.7.4
描述问题
测试命令:
这台电脑使用brew安装了llvm18工具链,因此测试编译时我传递了 toolchain、sdk和 ldflags 来链接到最新的libc++
但是在编译dxc时,CMAKE_SHARED_LINKER_FLAGS 参数并没有来自ldflags的参数,所以链接时会找不到一些内置函数
下面附加信息里有我这台电脑xmake生成的cmake config命令,可以看到
-DCMAKE_SHARED_LINKER_FLAGS
参数内没有ldflag设置的内容,不知道是不是失败的原因期待的结果
在设置ldflags时也可以成功编译
工程配置
附加信息和错误日志
生成的cmake命令
ninja编译报错日志
The text was updated successfully, but these errors were encountered: