Hello, I configured Nim to use Zig for compilation, and compiling into an executable works fine, but if I want to compile a static library, it throws an error. The key issue is that the error message is incomplete—what file exactly is missing?
PS C:\Users\Administrator\temp\testnim1\custom> nim c --app:staticlib --out:mylibrary.lib --noMain:on .\mylib.nim
Hint: used config file 'C:\me\tools\nim-2.2.4\config\nim.cfg' [Conf]
Hint: used config file 'C:\me\tools\nim-2.2.4\config\config.nims' [Conf]
Hint: used config file 'C:\Users\Administrator\AppData\Roaming\nim\nim.cfg' [Conf]
Hint: used config file 'C:\Users\Administrator\temp\testnim1\custom\nim.cfg' [Conf]
.....................................................................
CC: ../../../../../me/tools/nim-2.2.4/lib/system/exceptions.nim
CC: ../../../../../me/tools/nim-2.2.4/lib/std/private/digitsutils.nim
CC: ../../../../../me/tools/nim-2.2.4/lib/system/dollars.nim
CC: ../../../../../me/tools/nim-2.2.4/lib/std/syncio.nim
CC: ../../../../../me/tools/nim-2.2.4/lib/system.nim
CC: mylib.nim
Hint: [Link]
Error: invocation of external linker program failed. 系统找不到指定的文件。
2
PS C:\Users\Administrator\temp\testnim1\custom> cat .\nim.cfg
clang.exe = "C:/path/zigcc.bat"
clang.linkerexe="C:/path/zigcc.bat"
clang.ar = "C:/path/zigar.bat"
clang.alinkexe = "C:/path/zigar.bat"
cc = "clang"
cpu = "amd64"
os = "windows"
passC = "-target x86_64-windows-gnu"
passL = "-target x86_64-windows-gnu"
d = "debug"
I think it's the ar tool that is missing. But I don't see any example telling me how to set the path to the ar tool to execute the zig ar wrapper Related: https://forum.nim-lang.org/t/9165
You can pass --listcmd flag to Nim to see what it's trying to call.
Looking at source code it's probably llvm-ar you're missing.
Unfortunately, I don't see any way to overwrite this command. But, you can probably solve it by creating aliias llvm-ar batch script or you can skip linking step and link lib yourself.