I'm building a compiler in Rust based on LLVM IR, and I'm using Inkwell as a wrapper around LLVM C bindings (i.e. llvm-sys). When I'm building my codebase on WSL (Ubuntu 20.04) with LLVM installed (using the script suggested by llvm-sys) everything works fine, but I also want to compile it on Windows (MSVC).
I found out that binaries for Windows attached to official LLVM releases lack llvm-config.exe, which is required by llvm-sys, so I tried compiling LLVM from sources. I followed both of this tutorials: Getting Started (i.e. used Ninja to compile) and Getting Started using Visual Studio. In both cases, the compilation was successful and llvm-config.exe was properly created and working (i.e. printed help message when run), but when I tried compiling my own project (using cargo build), every time I got a linker error: "linking with link.exe failed: exit code: 1120", followed by a list of C functions that Inkwell was trying to call, but the linker couldn't find.
I'm pretty sure the reason for this is that something's wrong with my LLVM installation, but I have no idea what, and I couldn't find anything useful anywhere (the closest I found is this issue, but it wasn't helpful, because compiling with CMake still makes the compilation of my program exit with code 1120).
EDIT:
I managed to fix this issue by adding an additional flag for CMake when building LLVM. Essentially, CMake automatically recognizes your host architecture in the process, but it can confuse i686 with x86_64. Because I compiled my Rust application to x86_64, there was a mismatch between my application and the installed LLVM, which resulted in linking errors. Specifying LLVM_HOST_TRIPLE in the CMake invocation fixed the problem. The final version looked like this: cmake -S llvm -B build -G Ninja -DCMAKE_BUILD_TYPE=MinSizeRel -DLLVM_HOST_TRIPLE="x86_64-pc-windows-msvc" -DCMAKE_INSTALL_PREFIX="C:\some\path" -DLLVM_ENABLE_ASSERTIONS=ON.
Note: When using Inkwell, it is also important that you don't specify LLVM_TARGETS_TO_BUILD, as it results in linker errors for the omitted architectures.