Issue 147343
Summary Clang-cl: Allow choosing runtime library (e.g. UCRT)
Labels new issue
Assignees
Reporter caskeyking
    I am using `clang-cl` to cross-compile code for a windows target on a linux host.
I want to switch from linking my binaries with `msvcrt` to `ucrt`. By default, the `clang-cl` switches `/MD` and `/MT` add `/DEFAULTLIB:msvcrt.lib` and  `/DEFAULTLIB:libcmt.lib` respectively. These are translated into `--dependent-lib=` arguments for clang's `cc1`.

However, for [ucrt](https://learn.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=msvc-170), `/DEFAULTLIB:libucrt.lib` and `/DEFAULTLIB:ucrt.lib` are needed.

[#89642](https://github.com/llvm/llvm-project/pull/89642) should allow the user to disable the defaultlib, but `clang-cl` does not recognize this argument:
```
clang-cl --target=x86_64-pc-windows-msvc /winsysroot /tmp/xwin -fno-rtlib-defaultlib /c test.c /Fotest.obj
clang-cl: warning: argument unused during compilation: '-fno-rtlib-defaultlib' [-Wunused-command-line-argument]
```
The linker sees the `/DEFAULTLIB:libcmt.lib`, which prevents it from linking against `libucrt.lib`:
```
lld-link -verbose test.obj /out:test.exe
lld-link: Reading test.obj
lld-link: Directives: test.obj:  /DEFAULTLIB:libcmt.lib /DEFAULTLIB:oldnames.lib /DEFAULTLIB:uuid.lib /DEFAULTLIB:uuid.lib
```

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to