`-fms-runtime-lib` flags not work
Zig Version
0.12.0-dev.3666+a2b834e8c
Steps to Reproduce and Observed Behavior
I'm trying to use zig cc as a C compiler on Windows to produce dll, for this test code:
__declspec(dllexport) int add(int a, int b) {
return a + b;
}
the command line output:
zig cc -O3 -fms-runtime-lib=static -shared -o test.dll test_dll.c
zig: warning: argument unused during compilation: '-fms-runtime-lib=static' [-Wunused-command-line-argument]
and the dumpbin /imports outputs:
Dump of file test.dll
File Type: DLL
Section contains the following imports:
api-ms-win-crt-runtime-l1-1-0.dll
KERNEL32.dll
api-ms-win-crt-stdio-l1-1-0.dll
api-ms-win-crt-environment-l1-1-0.dll
api-ms-win-crt-heap-l1-1-0.dll
api-ms-win-crt-time-l1-1-0.dll
api-ms-win-crt-string-l1-1-0.dll
btw, I make a similar zig code:
export fn add(a: i32, b: i32) callconv(.C) i32 {
return a + b;
}
it produce 140k test.dll when I use zig cc, but only 4k when I use zig build-lib -dynamic.
Expected Behavior
Dump of file test.dll
File Type: DLL
Section contains the following imports:
KERNEL32.dll
@starwing Have you tried with -target x86_64-windows-msvc ? Or zig may use x86_64-windows-gnu (which is mingw-w64) as default, so the option for msvc won't work. (And Windows SDK has to be installed before. Of course it's not installed with zig, and zig will depend on it when x86_64-windows-msvc.)
However, with this option, I still cannot make it work. Some warnings are produced like this:
> zig.exe cc -o main.exe -target x86_64-windows-msvc -fms-runtime-lib=dll main.c
lld-link: warning: C:\Users\xxx\AppData\Local\zig\o\6aaeccb4026bbca8319d4396da13a2ca\main.obj: locally defined symbol imported: __acrt_iob_func (defined in libucrtd.lib(_file.obj)) [LNK4217]
lld-link: warning: C:\Users\xxx\AppData\Local\zig\o\6aaeccb4026bbca8319d4396da13a2ca\main.obj: locally defined symbol imported: __stdio_common_vsprintf (defined in libucrtd.lib(output.obj)) [LNK4217]
lld-link: warning: C:\Users\xxx\AppData\Local\zig\o\6aaeccb4026bbca8319d4396da13a2ca\main.obj: locally defined symbol imported: __stdio_common_vfprintf (defined in libucrtd.lib(output.obj)) [LNK4217]
And the dependencies and size of the resulting exe is not changed comparing to -fms-runtime-lib=static.
When optimization is enabled and -target x86_64-windows-msvc, zig cc will link to release version of UCRT. Or it will choose the debug version of UCRT (although no -g specified). --verbose will show these info.
When optimization is enabled and
-target x86_64-windows-msvc, zig cc will link to release version of UCRT. Or it will choose the debug version of UCRT (although no-gspecified).--verbosewill show these info.
Does zig cc link into msvc's static LIBCMT.lib? That's what I want to do.
- https://github.com/llvm/llvm-project/issues/129881