Linking to rustc_llvm with --llvm-root
If you link to rustc_llvm with a rustc configured with --llvm-root the path to the LLVM libraries is not passed to the linker resulting in linking errors
There are no static libraries which depend on LLVM right? So there is no reason linking to rustc_plugin would require linking in LLVM libraries?
Zoxc at 2016-01-17 07:47:18
Linking to LLVM doesn't happen on OS X or debian, but it does on x86_64-mingw-w64 with msys2
Zoxc at 2016-01-17 08:22:10
@DiamondLovesYou Do you think this is related to #27937? I know this used to work on one of your earlier
llvm-root-and-sharedbranches.Linking errors:
Compiling assembly v0.1.0 (file:///B:/Programmering/SandboxOS/AveryRust/kernel/arch/x64/multiboot) error: linking with `gcc` failed: exit code: 1 note: "gcc" "-Wl,--enable-long-section-names" "-fno-use-linker-plugin" "-Wl,--nxcompat" "-nostdlib" "-m64" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\dllcrt2.o" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\rsbegin.o" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "B:/Programmering/SandboxOS/AveryRust/build/cargo/target\\release\\deps\\assembly-bb6051f47b5bc242.0.o" "-o" "B:/Programmering/SandboxOS/AveryRust/build/cargo/target\\release\\deps\\assembly-bb6051f47b5bc242.dll" "B:/Programmering/SandboxOS/AveryRust/build/cargo/target\\release\\deps\\assembly-bb6051f47b5bc242.metadata.o" "-nodefaultlibs" "-L" "B:/Programmering/SandboxOS/AveryRust/build/cargo/target\\release\\deps" "-L" "B:/Programmering/SandboxOS/AveryRust/build/cargo/target\\release\\deps" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-Wl,-Bstatic" "-Wl,-Bdynamic" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "rustc_plugin-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "rustc_metadata-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "rustc-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "rustc_data_structures-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "graphviz-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "fmt_macros-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "arena-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "getopts-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "flate-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "rustc_back-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "rustc_front-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "syntax-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "term-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "rustc_llvm-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "rbml-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "serialize-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "log-ca1c970e" "-L" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-l" "std-ca1c970e" "-l" "psapi" "-l" "kernel32" "-l" "ole32" "-l" "LLVMInterpreter" "-l" "LLVMMCJIT" "-l" "LLVMExecutionEngine" "-l" "LLVMRuntimeDyld" "-l" "LLVMipo" "-l" "LLVMVectorize" "-l" "LLVMLinker" "-l" "LLVMIRReader" "-l" "LLVMAsmParser" "-l" "LLVMX86Disassembler" "-l" "LLVMX86AsmParser" "-l" "LLVMX86CodeGen" "-l" "LLVMSelectionDAG" "-l" "LLVMAsmPrinter" "-l" "LLVMCodeGen" "-l" "LLVMTarget" "-l" "LLVMScalarOpts" "-l" "LLVMInstCombine" "-l" "LLVMInstrumentation" "-l" "LLVMProfileData" "-l" "LLVMTransformUtils" "-l" "LLVMBitWriter" "-l" "LLVMAnalysis" "-l" "LLVMX86Desc" "-l" "LLVMObject" "-l" "LLVMMCParser" "-l" "LLVMBitReader" "-l" "LLVMMCDisassembler" "-l" "LLVMX86Info" "-l" "LLVMX86AsmPrinter" "-l" "LLVMMC" "-l" "LLVMX86Utils" "-l" "LLVMCore" "-l" "LLVMSupport" "-l" "psapi" "-l" "shell32" "-l" "ole32" "-l" "uuid" "-l" "stdc++" "-l" "gcc_eh" "-l" "ws2_32" "-l" "userenv" "-l" "shell32" "-l" "advapi32" "-shared" "-l" "compiler-rt" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-luser32" "-lkernel32" "B:\\Programmering\\SandboxOS\\AveryRust\\vendor\\rust\\install\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\rsend.o" note: X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMInterpreter X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMMCJIT X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMExecutionEngine X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMRuntimeDyld X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMipo X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMVectorize X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMLinker X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMIRReader X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMAsmParser X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMX86Disassembler X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMX86AsmParser X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMX86CodeGen X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMSelectionDAG X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMAsmPrinter X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMCodeGen X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMTarget X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMScalarOpts X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMInstCombine X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMInstrumentation X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMProfileData X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMTransformUtils X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMBitWriter X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMAnalysis X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMX86Desc X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMObject X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMMCParser X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMBitReader X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMMCDisassembler X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMX86Info X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMX86AsmPrinter X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMMC X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMX86Utils X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMCore X:/Programmer/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lLLVMSupport collect2.exe: error: ld returned 1 exit statusZoxc at 2016-01-21 06:49:25
@Zoxc The error you've provided is the result of a missing -L path, specifically the one pointing to where LLVM's
*.libs are located. In the normal case w.r.t. Rust's linking model, LLVM is statically linked intolibrustc_llvm(meaning an -L path to LLVM libs isn't needed/expected); however when LLVM is dynamic Rust will try to transitively link all shared/dynamic dependencies. Meaning every crate and their downstream dependencies which use any part ofrustc_llvmwill have the LLVM*.libs added to their linker args.Rust doesn't install any LLVM static or shared libraries (this includes MSVCs
.libfiles) into its target specific rustlibs folder (which, as you've discovered, is quite an issue for shared LLVM + MSVC Rust), let alone at all, which I bet is the underlying issue.Richard Diamond at 2016-01-21 18:43:05
You should only transitively link to dependencies of a dependency if the immediate dependency is a a static library.
rustc_llvmis shared so it does not need its dependencies to be linked.Zoxc at 2016-01-22 05:59:22
Well there is the case were an upstream Rust shared library has generic code which links to a native library. So I guess the behavior is justified.
That means we have to ensure LLVM's lib path is passed to the linker with
rustc_llvm. Can the metadata hold paths to libraries or do we need some other way of making this happen?Zoxc at 2016-01-22 08:46:28
@Zoxc
That means we have to ensure LLVM's lib path is passed to the linker with
rustc_llvm. Can the metadata hold paths to libraries or do we need some other way of making this happen?Metadata should not hold paths to deps. The path must be provided by
cargoorrustc.Richard Diamond at 2016-01-22 15:43:57
I believe in the transition to rustbuild everything about LLVM changed enough that this is either likely fixed or no longe relevant, so closing.
Alex Crichton at 2017-08-25 16:33:46
@alexcrichton I doubt that is true.
Zoxc at 2017-08-25 17:04:53
Same on Gentoo Linux after libraries were moved from
/usr/lib/to/usr/lib64/llvm/4/lib64/.O01eg at 2017-12-18 12:51:29
Triage: no idea what the status of this is.
Steve Klabnik at 2020-04-16 00:26:34
This needs instructions on how to reproduce the issue at least (ideally a set of shell commands, including how to obtain LLVM directories).
Mark Rousskov at 2024-01-07 14:03:17