0

I have a CMake based Windows library project that only links successfully with the MSVC link.exe due to some obscure third party library dependencies. However, I want to compile the project using the LLVM 21 toolchain.

This succeeds when building it from the command line like this

cmake.exe "-DCMAKE_C_COMPILER=C:/Program Files/LLVM/bin/clang.exe" "-DCMAKE_CXX_COMPILER=C:/Program Files/LLVM/bin/clang++.exe" -D CMAKE_CXX_FLAGS=-fuse-ld=link.exe -G Ninja -B C:\path\to\buildfolder

cmake.exe --build C:\path\to\buildfolder

However, when attempting to configure the same build in CLion by adding -D CMAKE_CXX_FLAGS=-fuse-ld=link.exe in the CMake Options field the linking stage fails because lld-link is invoked. The link command that is displayed in the build output starts like this

C:\Windows\system32\cmd.exe /C "cd . && C:\PROGRA~1\LLVM\bin\CLANG_~1.EXE -nostartfiles -nostdlib -fuse-ld=link.exe -O0 -g -Xclang -gcodeview -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd  -fuse-ld=lld-link -shared

So the -fuse-ld=link.exe flag is passed through but another second -fuse-ld=lld-link flag seems to be added automatically by CLion which overrides the manually specified flag. I found no option to avoid that or explicitly set up another linker for the toolchain. Is there any way to do this?

2
  • Have you seen the CMAKE_LINKER_TYPE variable? Commented Nov 8 at 3:54
  • 1
    How could I not see that? Yes, that does the trick! Thanks a lot for the hint Commented Nov 10 at 10:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.