Failed to link on Windows

Hey
I’m working on GitHub - thewh1teagle/whisper.zig
it uses whisper.cpp and libsndfile and it works well on macOS
However on Windows it failed with the following error:

error: lld-link: could not open 'libMSVCRT.a': No such file or directory
error: lld-link: could not open 'libOLDNAMES.a': No such file or directory
error: lld-link: could not open 'libmsvcprt.a': No such file or directory
error: the following command failed with 3 compilation errors:
C:\bin\zig\zig.exe build-exe -lwhisper -lggml -lsndfile -ODebug -I D:\whisper.zig\lib\whisper.cpp\src -I D:\whisper.zig\lib\whisper.cpp\src\include -I D:\whisper.zig\lib\whisper.cpp\include -I D:\whisper.zig\lib\whisper.cpp\ggml\include -I D:\whisper.zig\lib\libsndfile\include -L D:\whisper.zig\lib\whisper.cpp\build\src -L D:\whisper.zig\lib\whisper.cpp\build\src\Release -L D:\whisper.zig\lib\whisper.cpp\build\ggml\src -L D:\whisper.zig\lib\whisper.cpp\build\ggml\src\Release -L D:\whisper.zig\lib\libsndfile\build -L D:\whisper.zig\lib\libsndfile\build\Release -Mroot=D:\whisper.zig\src\main.zig -lc++ --cache-dir D:\whisper.zig\.zig-cache --global-cache-dir C:\Users\yaako\AppData\Local\zig --name whisper.zig --zig-lib-dir C:\bin\zig\lib\

Do you know why it tries to link this files? I don’t specified them in zig.build

From Google, it looks like libmsvcrt is part of libc. To link it, you can add -lc to your command.

I already try to link it but it doesn’t find the required files from MSVC

If you want to link libc from MSVC I think you need to use the MSVC target. The default target is gnu which uses MinGW

so -Dtarget=native-windows-msvc ?

For build-exe the argument might be -target native-windows-msvc

FYI, linking MSVC requires the files to be installed on the computer doing the building, so you would need to install visual studio. MinGW is bundled with zig.

1 Like

Thanks, I didn’t knew that the default target is GNU.
I tried to set the target to msvc and built with:

zig build -Dtarget=native-windows-msvc

But now it failed with:

install
└─ install whisper.zig
   └─ zig build-exe whisper.zig Debug native-windows-msvc 1 errors
error: sub-compilation of libcxxabi failed

libcxx kind of sounds like c++? Maybe you need to link libc++.

Here is an example that linked lib c++:

I use both c and c++ (whiser.cpp)
and link c++ with

exe.linkLibCpp();
exe.linkLibC();

inside build.zig

   └─ zig build-exe whisper.zig Debug native-windows-msvc 1 errors
error: sub-compilation of libcxxabi failed
 C:\bin\zig\zig.exe build-exe -lwhisper -lggml -lsndfile -ODebug -target native-windows-msvc -mcpu native -I D:\whisper.zig\lib\whisper.cpp\src -I D:\whisper.zig\lib\whisper.cpp\src\include -I D:\whisper.zig\lib\whisper.cpp\include -I D:\whisper.zig\lib\whisper.cpp\ggml\include -I D:\whisper.zig\lib\libsndfile\include -L D:\whisper.zig\lib\whisper.cpp\build\src -L D:\whisper.zig\lib\whisper.cpp\build\src\Release -L D:\whisper.zig\lib\whisper.cpp\build\ggml\src -L D:\whisper.zig\lib\whisper.cpp\build\ggml\src\Release -L D:\whisper.zig\lib\libsndfile\build -L D:\whisper.zig\lib\libsndfile\build\Release -Mroot=D:\whisper.zig\src\main.zig -lc++ -lc --cache-dir D:\whisper.zig\.zig-cache --global-cache-dir C:\Users\yaako\AppData\Local\zig --name whisper.zig --zig-lib-dir C:\bin\zig\lib\


C:\bin\zig\zig.exe : error: sub-compilation of libcxxabi failed
At line:1 char:1
+ C:\bin\zig\zig.exe build-exe -lwhisper -lggml -lsndfile -ODebug -targ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (error: sub-comp...ibcxxabi failed:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

I think that zig doesn’t support link c++ with msvc yet

but it didn’t worked even with mingw that comes with zig.

1 Like

Fixed by compile using msys2 clang64