Skip to content
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

Closed
ksgfk opened this issue Aug 1, 2024 · 6 comments
Labels

Comments

@ksgfk
Copy link

ksgfk commented Aug 1, 2024

Xmake 版本

v2.9.4

操作系统版本和架构

macOS Monterey 12.7.4

描述问题

测试命令:

xmake l scripts/test.lua --shallow -vD --toolchain=llvm --sdk=/usr/local/opt/llvm --ldflags="-L/usr/local/opt/llvm/lib/ -L/usr/local/opt/llvm/lib/c++ -Wl -rpath /usr/local/opt/llvm/lib/c++" directxshadercompiler_radray

这台电脑使用brew安装了llvm18工具链,因此测试编译时我传递了 toolchain、sdk和 ldflags 来链接到最新的libc++

但是在编译dxc时,CMAKE_SHARED_LINKER_FLAGS 参数并没有来自ldflags的参数,所以链接时会找不到一些内置函数

下面附加信息里有我这台电脑xmake生成的cmake config命令,可以看到-DCMAKE_SHARED_LINKER_FLAGS参数内没有ldflag设置的内容,不知道是不是失败的原因

期待的结果

在设置ldflags时也可以成功编译

工程配置

package("directxshadercompiler_radray")
    set_base("directxshadercompiler")
    local date = {
        ["1.8.2407"] = "2024_07_31_clang_cl"}
    if is_plat("windows") then
        add_urls("https://github.com/microsoft/DirectXShaderCompiler/releases/download/v$(version).zip", {version = function (version) return version .. "/dxc_" .. date[tostring(version)] end})
        add_versions("1.8.2407", "d6650a1b431fb24e47507b615c77f8a9717cd03e422ee12d4a1e98856f9ba7a6")
    elseif is_plat("linux") and is_arch("x86_64") then
        add_versions("v1.8.2407", "3e06cd31497bacfc2308017bfa3b228b9b762fc1a545186463e03a3356f61df4")
    elseif is_plat("macosx") then
        add_urls("https://github.com/microsoft/DirectXShaderCompiler.git")
        add_versions("v1.8.2407", "3e06cd31497bacfc2308017bfa3b228b9b762fc1a545186463e03a3356f61df4")
    end

    on_install("macosx", function (package)
        local build_dir = path.join(package:cachedir(), "build")
        local git_dir = path.join(package:cachedir(), "source", package:name())
        local configs = {
            "-B " .. build_dir,
            "-C " .. path.join(git_dir, "cmake", "caches", "PredefinedParams.cmake"),
            "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"),
        }
        import("package.tools.cmake").build(package, configs, {cmake_generator = "Ninja", buildir = build_dir})

        os.cp(path.join(build_dir, "bin", "dxc"), package:installdir("bin"))
        os.cp("include/dxc", package:installdir("include"))
        os.cp(path.join(build_dir, "lib", "libdxcompiler.dylib*"), package:installdir("lib"))
        package:addenv("PATH", "bin")
    end)

附加信息和错误日志

生成的cmake命令

/usr/local/bin/cmake 
"-B /Users/admin/.xmake/cache/packages/2408/d/directxshadercompiler_radray/v1.8.2407/build" 
"-C /Users/admin/.xmake/cache/packages/2408/d/directxshadercompiler_radray/v1.8.2407/source/directxshadercompiler_radray/cmake/caches/PredefinedParams.cmake" 
-DCMAKE_BUILD_TYPE=Release 
-DCMAKE_INSTALL_PREFIX=/Users/admin/.xmake/packages/d/directxshadercompiler_radray/v1.8.2407/801d85b896bd4df2beeda774b8048227 
-DCMAKE_INSTALL_LIBDIR:PATH=lib 
-G Ninja 
-DCMAKE_POSITION_INDEPENDENT_CODE=ON 
-DCMAKE_STATIC_LINKER_FLAGS= 
-DCMAKE_C_COMPILER=/usr/local/opt/llvm/bin/clang 
"-DCMAKE_C_FLAGS=-m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk" "-DCMAKE_CXX_FLAGS=-m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk" 
-DCMAKE_RC_COMPILER=/usr/local/opt/llvm/bin/llvm-rc 
-DCMAKE_AR=/usr/local/opt/llvm/bin/llvm-ar 
-DCMAKE_RANLIB=/usr/local/opt/llvm/bin/llvm-ranlib 
-DCMAKE_ASM_COMPILER=/usr/local/opt/llvm/bin/clang 
"-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++\" -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk" 
-DCMAKE_ASM_FLAGS=-m64 
"-DCMAKE_CXX_LINK_EXECUTABLE=/usr/local/opt/llvm/bin/clang++ <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>" 
-DCMAKE_CXX_COMPILER=/usr/local/opt/llvm/bin/clang++ 
"-DCMAKE_SHARED_LINKER_FLAGS=-m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk" 
"-DCMAKE_SHARED_LINKER_FLAGS_RELEASE=-m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk" 
"-DCMAKE_CXX_FLAGS_RELEASE=-m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -O3 -DNDEBUG" 
"-DCMAKE_EXE_LINKER_FLAGS_RELEASE=\"-L/usr/local/opt/llvm/lib/ -L/usr/local/opt/llvm/lib/c++ -Wl -rpath /usr/local/opt/llvm/lib/c++\" -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk" 
-DCMAKE_STATIC_LINKER_FLAGS_RELEASE= "-DCMAKE_C_FLAGS_RELEASE=-m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -O3 -DNDEBUG" 
/Users/admin/.xmake/cache/packages/2408/d/directxshadercompiler_radray/v1.8.2407/source/directxshadercompiler_radray

ninja编译报错日志

/usr/local/opt/llvm/bin/clang++ -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -fPIC -fvisibility-inlines-hidden -fvisibility=hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wimplicit-fallthrough -Wcast-qual -Wno-unknown-pragmas -Wno-unused-but-set-variable -Wno-deprecated-copy -Wmissing-field-initializers -pedantic -Wno-long-long -Wno-switch -Wno-comment -fcolor-diagnostics -fms-extensions -Wno-language-extension-token -fno-common -Woverloaded-virtual -fno-strict-aliasing -Wno-nested-anon-types -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -O3 -DNDEBUG -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -mmacosx-version-min=12.7 -dynamiclib -Wl,-headerpad_max_install_names -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk  -Wl,-dead_strip -Wl,-install_name,@rpath/libdxcompiler.dylib  -compatibility_version 3.7.0 -current_version 3.7.0 -o lib/libdxcompiler.dylib   tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcapi.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcassembler.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxclibrary.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcompilerobj.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/DXCompiler.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcfilesystem.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcutil.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcdisassembler.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcpdbutils.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxillib.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcvalidator.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxclinker.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcshadersourceinfo.cpp.o  -Wl,-rpath,@executable_path/../lib  lib/libLLVMAnalysis.a  lib/libLLVMAsmParser.a  lib/libLLVMBitReader.a  lib/libLLVMBitWriter.a  lib/libLLVMCore.a  lib/libLLVMDxcSupport.a  lib/libLLVMDXIL.a  lib/libLLVMDxilContainer.a  lib/libLLVMDxilPIXPasses.a  lib/libLLVMDxilRootSignature.a  lib/libLLVMDxcBindingTable.a  lib/libLLVMHLSL.a  lib/libLLVMInstCombine.a  lib/libLLVMipa.a  lib/libLLVMipo.a  lib/libLLVMIRReader.a  lib/libLLVMLinker.a  lib/libLLVMMSSupport.a  lib/libLLVMOption.a  lib/libLLVMProfileData.a  lib/libLLVMScalarOpts.a  lib/libLLVMSupport.a  lib/libLLVMTarget.a  lib/libLLVMTransformUtils.a  lib/libLLVMVectorize.a  lib/libLLVMDxilCompression.a  lib/libLLVMPassPrinters.a  lib/libclangIndex.a  lib/libclangRewrite.a  lib/libclangCodeGen.a  lib/libclangRewriteFrontend.a  lib/libclangFrontend.a  lib/libclangDriver.a  lib/libclangSema.a  lib/libclangEdit.a  lib/libclangAST.a  lib/libclangCodeGen.a  lib/libclangLex.a  lib/libclangTooling.a  lib/libclangBasic.a  lib/libclang.a  lib/libclangSPIRV.a  lib/libLLVMPasses.a  lib/libclangIndex.a  lib/libclangFormat.a  lib/libclangTooling.a  lib/libclangToolingCore.a  lib/libclangRewrite.a  lib/libclangASTMatchers.a  -ldl  lib/libclangCodeGen.a  lib/libclangFrontend.a  lib/libclangSema.a  lib/libclangEdit.a  lib/libclangAST.a  lib/libclangParse.a  lib/libclangAnalysis.a  lib/libclangCodeGen.a  lib/libclangFrontend.a  lib/libclangSema.a  lib/libclangEdit.a  lib/libclangAST.a  lib/libclangParse.a  lib/libclangAnalysis.a  lib/libLLVMDxilRootSignature.a  lib/libLLVMipo.a  lib/libLLVMVectorize.a  lib/libLLVMIRReader.a  lib/libLLVMAsmParser.a  lib/libLLVMLinker.a  lib/libLLVMScalarOpts.a  lib/libLLVMInstCombine.a  lib/libLLVMProfileData.a  lib/libLLVMTarget.a  lib/libclangDriver.a  lib/libLLVMOption.a  lib/libLLVMHLSL.a  lib/libLLVMDxilContainer.a  lib/libLLVMBitWriter.a  lib/libLLVMTransformUtils.a  lib/libLLVMDxcBindingTable.a  lib/libLLVMipa.a  lib/libLLVMAnalysis.a  lib/libLLVMDXIL.a  lib/libLLVMBitReader.a  lib/libclangLex.a  lib/libclangBasic.a  lib/libLLVMCore.a  lib/libLLVMDxcSupport.a  lib/libLLVMSupport.a  lib/libLLVMMSSupport.a  -lpthread  -lz  -lm  lib/libSPIRV-Tools-opt.a  lib/libSPIRV-Tools.a && :
Undefined symbols for architecture x86_64:
  "std::__1::__libcpp_verbose_abort(char const*, ...)", referenced from:
      std::__1::__throw_bad_function_call[abi:nn180100]() in libSPIRV-Tools.a(libspirv.cpp.o)
      std::__1::__throw_length_error[abi:nn180100](char const*) in libSPIRV-Tools.a(libspirv.cpp.o)
      std::__throw_bad_array_new_length[abi:nn180100]() in libSPIRV-Tools-opt.a(optimizer.cpp.o)
      std::__1::__throw_out_of_range[abi:nn180100](char const*) in libSPIRV-Tools-opt.a(optimizer.cpp.o)
ld: symbol(s) not found for architecture x86_64
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
@ksgfk ksgfk added the bug label Aug 1, 2024
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Title: A link error occurs when compiling dxc when customizing the package, toolchain, sdk, and ldflags under macos.

@ksgfk
Copy link
Author

ksgfk commented Aug 2, 2024

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工程,使用以上命令是可以编译成功的,感觉就是CMAKE_SHARED_LINKER_FLAGS参数不对的原因

@waruqi
Copy link
Member

waruqi commented Aug 2, 2024

既然自己本地可以,那你对下最后的 link flags ,看下差异。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Since you can do it locally, check the last link flags and see the difference.

@ksgfk
Copy link
Author

ksgfk commented Aug 2, 2024

既然自己本地可以,那你对下最后的 link flags ,看下差异。

这是xmake调用cmake config生成的ninja命令片段

#############################################
# Link the shared library lib/libdxcompiler.dylib

build lib/libdxcompiler.dylib: CXX_SHARED_LIBRARY_LINKER__dxcompiler_Release tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcapi.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcassembler.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxclibrary.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcompilerobj.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/DXCompiler.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcfilesystem.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcutil.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcdisassembler.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcpdbutils.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxillib.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcvalidator.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxclinker.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcshadersourceinfo.cpp.o | lib/libLLVMAnalysis.a lib/libLLVMAsmParser.a lib/libLLVMBitReader.a lib/libLLVMBitWriter.a lib/libLLVMCore.a lib/libLLVMDxcSupport.a lib/libLLVMDXIL.a lib/libLLVMDxilContainer.a lib/libLLVMDxilPIXPasses.a lib/libLLVMDxilRootSignature.a lib/libLLVMDxcBindingTable.a lib/libLLVMHLSL.a lib/libLLVMInstCombine.a lib/libLLVMipa.a lib/libLLVMipo.a lib/libLLVMIRReader.a lib/libLLVMLinker.a lib/libLLVMMSSupport.a lib/libLLVMOption.a lib/libLLVMProfileData.a lib/libLLVMScalarOpts.a lib/libLLVMSupport.a lib/libLLVMTarget.a lib/libLLVMTransformUtils.a lib/libLLVMVectorize.a lib/libLLVMDxilCompression.a lib/libLLVMPassPrinters.a lib/libclangIndex.a lib/libclangRewrite.a lib/libclangCodeGen.a lib/libclangRewriteFrontend.a lib/libclangFrontend.a lib/libclangDriver.a lib/libclangSema.a lib/libclangEdit.a lib/libclangAST.a lib/libclangCodeGen.a lib/libclangLex.a lib/libclangTooling.a lib/libclangBasic.a lib/libclang.a lib/libclangSPIRV.a lib/libLLVMPasses.a lib/libclangIndex.a lib/libclangFormat.a lib/libclangTooling.a lib/libclangToolingCore.a lib/libclangRewrite.a lib/libclangASTMatchers.a lib/libclangCodeGen.a lib/libclangFrontend.a lib/libclangSema.a lib/libclangEdit.a lib/libclangAST.a lib/libclangParse.a lib/libclangAnalysis.a lib/libclangCodeGen.a lib/libclangFrontend.a lib/libclangSema.a lib/libclangEdit.a lib/libclangAST.a lib/libclangParse.a lib/libclangAnalysis.a lib/libLLVMDxilRootSignature.a lib/libLLVMipo.a lib/libLLVMVectorize.a lib/libLLVMIRReader.a lib/libLLVMAsmParser.a lib/libLLVMLinker.a lib/libLLVMScalarOpts.a lib/libLLVMInstCombine.a lib/libLLVMProfileData.a lib/libLLVMTarget.a lib/libclangDriver.a lib/libLLVMOption.a lib/libLLVMHLSL.a lib/libLLVMDxilContainer.a lib/libLLVMBitWriter.a lib/libLLVMTransformUtils.a lib/libLLVMDxcBindingTable.a lib/libLLVMipa.a lib/libLLVMAnalysis.a lib/libLLVMDXIL.a lib/libLLVMBitReader.a lib/libclangLex.a lib/libclangBasic.a lib/libLLVMCore.a lib/libLLVMDxcSupport.a lib/libLLVMSupport.a lib/libLLVMMSSupport.a lib/libSPIRV-Tools-opt.a lib/libSPIRV-Tools.a || include/dxc/HCTGen include/dxc/Support/TablegenHLSLOptions lib/libLLVMAnalysis.a lib/libLLVMAsmParser.a lib/libLLVMBitReader.a lib/libLLVMBitWriter.a lib/libLLVMCore.a lib/libLLVMDXIL.a lib/libLLVMDxcBindingTable.a lib/libLLVMDxcSupport.a lib/libLLVMDxilCompression.a lib/libLLVMDxilContainer.a lib/libLLVMDxilPIXPasses.a lib/libLLVMDxilRootSignature.a lib/libLLVMHLSL.a lib/libLLVMIRReader.a lib/libLLVMInstCombine.a lib/libLLVMLinker.a lib/libLLVMMSSupport.a lib/libLLVMOption.a lib/libLLVMPassPrinters.a lib/libLLVMPasses.a lib/libLLVMProfileData.a lib/libLLVMScalarOpts.a lib/libLLVMSupport.a lib/libLLVMTarget.a lib/libLLVMTransformUtils.a lib/libLLVMVectorize.a lib/libLLVMipa.a lib/libLLVMipo.a lib/libSPIRV-Tools-opt.a lib/libSPIRV-Tools.a lib/libclang.a lib/libclangAST.a lib/libclangASTMatchers.a lib/libclangAnalysis.a lib/libclangBasic.a lib/libclangCodeGen.a lib/libclangDriver.a lib/libclangEdit.a lib/libclangFormat.a lib/libclangFrontend.a lib/libclangIndex.a lib/libclangLex.a lib/libclangParse.a lib/libclangRewrite.a lib/libclangRewriteFrontend.a lib/libclangSPIRV.a lib/libclangSema.a lib/libclangTooling.a lib/libclangToolingCore.a tools/clang/include/clang/AST/ClangAttrClasses tools/clang/include/clang/AST/ClangAttrDump tools/clang/include/clang/AST/ClangAttrImpl tools/clang/include/clang/AST/ClangAttrVisitor tools/clang/include/clang/AST/ClangCommentCommandInfo tools/clang/include/clang/AST/ClangCommentCommandList tools/clang/include/clang/AST/ClangCommentHTMLNamedCharacterReferences tools/clang/include/clang/AST/ClangCommentHTMLTags tools/clang/include/clang/AST/ClangCommentHTMLTagsProperties tools/clang/include/clang/AST/ClangCommentNodes tools/clang/include/clang/AST/ClangDeclNodes tools/clang/include/clang/AST/ClangStmtNodes tools/clang/include/clang/Basic/ClangAttrHasAttributeImpl tools/clang/include/clang/Basic/ClangAttrList tools/clang/include/clang/Basic/ClangDiagnosticAST tools/clang/include/clang/Basic/ClangDiagnosticAnalysis tools/clang/include/clang/Basic/ClangDiagnosticComment tools/clang/include/clang/Basic/ClangDiagnosticCommon tools/clang/include/clang/Basic/ClangDiagnosticDriver tools/clang/include/clang/Basic/ClangDiagnosticFrontend tools/clang/include/clang/Basic/ClangDiagnosticGroups tools/clang/include/clang/Basic/ClangDiagnosticIndexName tools/clang/include/clang/Basic/ClangDiagnosticLex tools/clang/include/clang/Basic/ClangDiagnosticParse tools/clang/include/clang/Basic/ClangDiagnosticSema tools/clang/include/clang/Basic/ClangDiagnosticSerialization tools/clang/include/clang/Parse/ClangAttrParserStringSwitches tools/clang/include/clang/Sema/ClangAttrParsedAttrImpl tools/clang/include/clang/Sema/ClangAttrParsedAttrKinds tools/clang/include/clang/Sema/ClangAttrParsedAttrList tools/clang/include/clang/Sema/ClangAttrSpellingListIndex tools/clang/include/clang/Sema/ClangAttrTemplateInstantiate tools/clang/include/clang/Serialization/ClangAttrPCHRead tools/clang/include/clang/Serialization/ClangAttrPCHWrite
  ARCH_FLAGS = -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -mmacosx-version-min=12.7
  LANGUAGE_COMPILE_FLAGS = -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -fPIC -fvisibility-inlines-hidden -fvisibility=hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wimplicit-fallthrough -Wcast-qual -Wno-unknown-pragmas -Wno-unused-but-set-variable -Wno-deprecated-copy -Wmissing-field-initializers -pedantic -Wno-long-long -Wno-switch -Wno-comment -fcolor-diagnostics -fms-extensions -Wno-language-extension-token -fno-common -Woverloaded-virtual -fno-strict-aliasing -Wno-nested-anon-types -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -O3 -DNDEBUG
  LINK_FLAGS = -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk  -Wl,-dead_strip -Wl,-install_name,@rpath/libdxcompiler.dylib  -compatibility_version 3.7.0 -current_version 3.7.0
  LINK_LIBRARIES = -Wl,-rpath,@executable_path/../lib  lib/libLLVMAnalysis.a  lib/libLLVMAsmParser.a  lib/libLLVMBitReader.a  lib/libLLVMBitWriter.a  lib/libLLVMCore.a  lib/libLLVMDxcSupport.a  lib/libLLVMDXIL.a  lib/libLLVMDxilContainer.a  lib/libLLVMDxilPIXPasses.a  lib/libLLVMDxilRootSignature.a  lib/libLLVMDxcBindingTable.a  lib/libLLVMHLSL.a  lib/libLLVMInstCombine.a  lib/libLLVMipa.a  lib/libLLVMipo.a  lib/libLLVMIRReader.a  lib/libLLVMLinker.a  lib/libLLVMMSSupport.a  lib/libLLVMOption.a  lib/libLLVMProfileData.a  lib/libLLVMScalarOpts.a  lib/libLLVMSupport.a  lib/libLLVMTarget.a  lib/libLLVMTransformUtils.a  lib/libLLVMVectorize.a  lib/libLLVMDxilCompression.a  lib/libLLVMPassPrinters.a  lib/libclangIndex.a  lib/libclangRewrite.a  lib/libclangCodeGen.a  lib/libclangRewriteFrontend.a  lib/libclangFrontend.a  lib/libclangDriver.a  lib/libclangSema.a  lib/libclangEdit.a  lib/libclangAST.a  lib/libclangCodeGen.a  lib/libclangLex.a  lib/libclangTooling.a  lib/libclangBasic.a  lib/libclang.a  lib/libclangSPIRV.a  lib/libLLVMPasses.a  lib/libclangIndex.a  lib/libclangFormat.a  lib/libclangTooling.a  lib/libclangToolingCore.a  lib/libclangRewrite.a  lib/libclangASTMatchers.a  -ldl  lib/libclangCodeGen.a  lib/libclangFrontend.a  lib/libclangSema.a  lib/libclangEdit.a  lib/libclangAST.a  lib/libclangParse.a  lib/libclangAnalysis.a  lib/libclangCodeGen.a  lib/libclangFrontend.a  lib/libclangSema.a  lib/libclangEdit.a  lib/libclangAST.a  lib/libclangParse.a  lib/libclangAnalysis.a  lib/libLLVMDxilRootSignature.a  lib/libLLVMipo.a  lib/libLLVMVectorize.a  lib/libLLVMIRReader.a  lib/libLLVMAsmParser.a  lib/libLLVMLinker.a  lib/libLLVMScalarOpts.a  lib/libLLVMInstCombine.a  lib/libLLVMProfileData.a  lib/libLLVMTarget.a  lib/libclangDriver.a  lib/libLLVMOption.a  lib/libLLVMHLSL.a  lib/libLLVMDxilContainer.a  lib/libLLVMBitWriter.a  lib/libLLVMTransformUtils.a  lib/libLLVMDxcBindingTable.a  lib/libLLVMipa.a  lib/libLLVMAnalysis.a  lib/libLLVMDXIL.a  lib/libLLVMBitReader.a  lib/libclangLex.a  lib/libclangBasic.a  lib/libLLVMCore.a  lib/libLLVMDxcSupport.a  lib/libLLVMSupport.a  lib/libLLVMMSSupport.a  -lpthread  -lz  -lm  lib/libSPIRV-Tools-opt.a  lib/libSPIRV-Tools.a
  OBJECT_DIR = tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir
  POST_BUILD = :
  PRE_LINK = :
  TARGET_FILE = lib/libdxcompiler.dylib
  TARGET_PDB = dxcompiler.dylib.dbg

这个是用上面手敲的cmake命令生成的ninja命令片段

#############################################
# Link the shared library lib/libdxcompiler.dylib

build lib/libdxcompiler.dylib: CXX_SHARED_LIBRARY_LINKER__dxcompiler_Release tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcapi.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcassembler.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxclibrary.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcompilerobj.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/DXCompiler.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcfilesystem.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcutil.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcdisassembler.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcpdbutils.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxillib.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcvalidator.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxclinker.cpp.o tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir/dxcshadersourceinfo.cpp.o | lib/libLLVMAnalysis.a lib/libLLVMAsmParser.a lib/libLLVMBitReader.a lib/libLLVMBitWriter.a lib/libLLVMCore.a lib/libLLVMDxcSupport.a lib/libLLVMDXIL.a lib/libLLVMDxilContainer.a lib/libLLVMDxilPIXPasses.a lib/libLLVMDxilRootSignature.a lib/libLLVMDxcBindingTable.a lib/libLLVMHLSL.a lib/libLLVMInstCombine.a lib/libLLVMipa.a lib/libLLVMipo.a lib/libLLVMIRReader.a lib/libLLVMLinker.a lib/libLLVMMSSupport.a lib/libLLVMOption.a lib/libLLVMProfileData.a lib/libLLVMScalarOpts.a lib/libLLVMSupport.a lib/libLLVMTarget.a lib/libLLVMTransformUtils.a lib/libLLVMVectorize.a lib/libLLVMDxilCompression.a lib/libLLVMPassPrinters.a lib/libclangIndex.a lib/libclangRewrite.a lib/libclangCodeGen.a lib/libclangRewriteFrontend.a lib/libclangFrontend.a lib/libclangDriver.a lib/libclangSema.a lib/libclangEdit.a lib/libclangAST.a lib/libclangCodeGen.a lib/libclangLex.a lib/libclangTooling.a lib/libclangBasic.a lib/libclang.a lib/libclangSPIRV.a lib/libLLVMPasses.a lib/libclangIndex.a lib/libclangFormat.a lib/libclangTooling.a lib/libclangToolingCore.a lib/libclangRewrite.a lib/libclangASTMatchers.a lib/libclangCodeGen.a lib/libclangFrontend.a lib/libclangSema.a lib/libclangEdit.a lib/libclangAST.a lib/libclangParse.a lib/libclangAnalysis.a lib/libclangCodeGen.a lib/libclangFrontend.a lib/libclangSema.a lib/libclangEdit.a lib/libclangAST.a lib/libclangParse.a lib/libclangAnalysis.a lib/libLLVMDxilRootSignature.a lib/libLLVMipo.a lib/libLLVMVectorize.a lib/libLLVMIRReader.a lib/libLLVMAsmParser.a lib/libLLVMLinker.a lib/libLLVMScalarOpts.a lib/libLLVMInstCombine.a lib/libLLVMProfileData.a lib/libLLVMTarget.a lib/libclangDriver.a lib/libLLVMOption.a lib/libLLVMHLSL.a lib/libLLVMDxilContainer.a lib/libLLVMBitWriter.a lib/libLLVMTransformUtils.a lib/libLLVMDxcBindingTable.a lib/libLLVMipa.a lib/libLLVMAnalysis.a lib/libLLVMDXIL.a lib/libLLVMBitReader.a lib/libclangLex.a lib/libclangBasic.a lib/libLLVMCore.a lib/libLLVMDxcSupport.a lib/libLLVMSupport.a lib/libLLVMMSSupport.a lib/libSPIRV-Tools-opt.a lib/libSPIRV-Tools.a || include/dxc/HCTGen include/dxc/Support/TablegenHLSLOptions lib/libLLVMAnalysis.a lib/libLLVMAsmParser.a lib/libLLVMBitReader.a lib/libLLVMBitWriter.a lib/libLLVMCore.a lib/libLLVMDXIL.a lib/libLLVMDxcBindingTable.a lib/libLLVMDxcSupport.a lib/libLLVMDxilCompression.a lib/libLLVMDxilContainer.a lib/libLLVMDxilPIXPasses.a lib/libLLVMDxilRootSignature.a lib/libLLVMHLSL.a lib/libLLVMIRReader.a lib/libLLVMInstCombine.a lib/libLLVMLinker.a lib/libLLVMMSSupport.a lib/libLLVMOption.a lib/libLLVMPassPrinters.a lib/libLLVMPasses.a lib/libLLVMProfileData.a lib/libLLVMScalarOpts.a lib/libLLVMSupport.a lib/libLLVMTarget.a lib/libLLVMTransformUtils.a lib/libLLVMVectorize.a lib/libLLVMipa.a lib/libLLVMipo.a lib/libSPIRV-Tools-opt.a lib/libSPIRV-Tools.a lib/libclang.a lib/libclangAST.a lib/libclangASTMatchers.a lib/libclangAnalysis.a lib/libclangBasic.a lib/libclangCodeGen.a lib/libclangDriver.a lib/libclangEdit.a lib/libclangFormat.a lib/libclangFrontend.a lib/libclangIndex.a lib/libclangLex.a lib/libclangParse.a lib/libclangRewrite.a lib/libclangRewriteFrontend.a lib/libclangSPIRV.a lib/libclangSema.a lib/libclangTooling.a lib/libclangToolingCore.a tools/clang/include/clang/AST/ClangAttrClasses tools/clang/include/clang/AST/ClangAttrDump tools/clang/include/clang/AST/ClangAttrImpl tools/clang/include/clang/AST/ClangAttrVisitor tools/clang/include/clang/AST/ClangCommentCommandInfo tools/clang/include/clang/AST/ClangCommentCommandList tools/clang/include/clang/AST/ClangCommentHTMLNamedCharacterReferences tools/clang/include/clang/AST/ClangCommentHTMLTags tools/clang/include/clang/AST/ClangCommentHTMLTagsProperties tools/clang/include/clang/AST/ClangCommentNodes tools/clang/include/clang/AST/ClangDeclNodes tools/clang/include/clang/AST/ClangStmtNodes tools/clang/include/clang/Basic/ClangAttrHasAttributeImpl tools/clang/include/clang/Basic/ClangAttrList tools/clang/include/clang/Basic/ClangDiagnosticAST tools/clang/include/clang/Basic/ClangDiagnosticAnalysis tools/clang/include/clang/Basic/ClangDiagnosticComment tools/clang/include/clang/Basic/ClangDiagnosticCommon tools/clang/include/clang/Basic/ClangDiagnosticDriver tools/clang/include/clang/Basic/ClangDiagnosticFrontend tools/clang/include/clang/Basic/ClangDiagnosticGroups tools/clang/include/clang/Basic/ClangDiagnosticIndexName tools/clang/include/clang/Basic/ClangDiagnosticLex tools/clang/include/clang/Basic/ClangDiagnosticParse tools/clang/include/clang/Basic/ClangDiagnosticSema tools/clang/include/clang/Basic/ClangDiagnosticSerialization tools/clang/include/clang/Parse/ClangAttrParserStringSwitches tools/clang/include/clang/Sema/ClangAttrParsedAttrImpl tools/clang/include/clang/Sema/ClangAttrParsedAttrKinds tools/clang/include/clang/Sema/ClangAttrParsedAttrList tools/clang/include/clang/Sema/ClangAttrSpellingListIndex tools/clang/include/clang/Sema/ClangAttrTemplateInstantiate tools/clang/include/clang/Serialization/ClangAttrPCHRead tools/clang/include/clang/Serialization/ClangAttrPCHWrite
  ARCH_FLAGS = -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -mmacosx-version-min=12.7
  LANGUAGE_COMPILE_FLAGS = -fPIC -fvisibility-inlines-hidden -fvisibility=hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wimplicit-fallthrough -Wcast-qual -Wno-unknown-pragmas -Wno-unused-but-set-variable -Wno-deprecated-copy -Wmissing-field-initializers -pedantic -Wno-long-long -Wno-switch -Wno-comment -fcolor-diagnostics -fms-extensions -Wno-language-extension-token -fno-common -Woverloaded-virtual -fno-strict-aliasing -Wno-nested-anon-types -O3 -DNDEBUG
  LINK_FLAGS = -L/usr/local/opt/llvm/lib/ -L/usr/local/opt/llvm/lib/c++ -Wl -rpath /usr/local/opt/llvm/lib/c++   -Wl,-dead_strip -Wl,-install_name,@rpath/libdxcompiler.dylib  -compatibility_version 3.7.0 -current_version 3.7.0
  LINK_LIBRARIES = -Wl,-rpath,@executable_path/../lib  lib/libLLVMAnalysis.a  lib/libLLVMAsmParser.a  lib/libLLVMBitReader.a  lib/libLLVMBitWriter.a  lib/libLLVMCore.a  lib/libLLVMDxcSupport.a  lib/libLLVMDXIL.a  lib/libLLVMDxilContainer.a  lib/libLLVMDxilPIXPasses.a  lib/libLLVMDxilRootSignature.a  lib/libLLVMDxcBindingTable.a  lib/libLLVMHLSL.a  lib/libLLVMInstCombine.a  lib/libLLVMipa.a  lib/libLLVMipo.a  lib/libLLVMIRReader.a  lib/libLLVMLinker.a  lib/libLLVMMSSupport.a  lib/libLLVMOption.a  lib/libLLVMProfileData.a  lib/libLLVMScalarOpts.a  lib/libLLVMSupport.a  lib/libLLVMTarget.a  lib/libLLVMTransformUtils.a  lib/libLLVMVectorize.a  lib/libLLVMDxilCompression.a  lib/libLLVMPassPrinters.a  lib/libclangIndex.a  lib/libclangRewrite.a  lib/libclangCodeGen.a  lib/libclangRewriteFrontend.a  lib/libclangFrontend.a  lib/libclangDriver.a  lib/libclangSema.a  lib/libclangEdit.a  lib/libclangAST.a  lib/libclangCodeGen.a  lib/libclangLex.a  lib/libclangTooling.a  lib/libclangBasic.a  lib/libclang.a  lib/libclangSPIRV.a  lib/libLLVMPasses.a  lib/libclangIndex.a  lib/libclangFormat.a  lib/libclangTooling.a  lib/libclangToolingCore.a  lib/libclangRewrite.a  lib/libclangASTMatchers.a  -ldl  lib/libclangCodeGen.a  lib/libclangFrontend.a  lib/libclangSema.a  lib/libclangEdit.a  lib/libclangAST.a  lib/libclangParse.a  lib/libclangAnalysis.a  lib/libclangCodeGen.a  lib/libclangFrontend.a  lib/libclangSema.a  lib/libclangEdit.a  lib/libclangAST.a  lib/libclangParse.a  lib/libclangAnalysis.a  lib/libLLVMDxilRootSignature.a  lib/libLLVMipo.a  lib/libLLVMVectorize.a  lib/libLLVMIRReader.a  lib/libLLVMAsmParser.a  lib/libLLVMLinker.a  lib/libLLVMScalarOpts.a  lib/libLLVMInstCombine.a  lib/libLLVMProfileData.a  lib/libLLVMTarget.a  lib/libclangDriver.a  lib/libLLVMOption.a  lib/libLLVMHLSL.a  lib/libLLVMDxilContainer.a  lib/libLLVMBitWriter.a  lib/libLLVMTransformUtils.a  lib/libLLVMDxcBindingTable.a  lib/libLLVMipa.a  lib/libLLVMAnalysis.a  lib/libLLVMDXIL.a  lib/libLLVMBitReader.a  lib/libclangLex.a  lib/libclangBasic.a  lib/libLLVMCore.a  lib/libLLVMDxcSupport.a  lib/libLLVMSupport.a  lib/libLLVMMSSupport.a  -lpthread  -lz  -lm  lib/libSPIRV-Tools-opt.a  lib/libSPIRV-Tools.a
  OBJECT_DIR = tools/clang/tools/dxcompiler/CMakeFiles/dxcompiler.dir
  POST_BUILD = :
  PRE_LINK = :
  TARGET_FILE = lib/libdxcompiler.dylib
  TARGET_PDB = dxcompiler.dylib.dbg

LINK_FLAGS 参数确实不一样,手敲这个才是对的,是我传入的CMAKE_SHARED_LINKER_FLAGS

@ksgfk
Copy link
Author

ksgfk commented Nov 4, 2024

破案了,原来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()

@ksgfk ksgfk closed this as completed Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants