clang.exe = "zigcc.bat"
clang.linkerexe="zigcc.bat"
enable --listCmd can see nim calls the ar rcs command to build an staticlib for gcc If I enable cc to clang, it will call llvm-ar
PS C:\Users\Administrator\temp\testpurenim> nim c --app:staticlib --noMain --nimMainPrefix:mylib_ --out:mylib.lib --listCmd --nimcache:gogo xx.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]
.....................................................................
CC: ../../../../me/tools/nim-2.2.4/lib/system/exceptions.nim: C:\me\tools\nim-2.2.4\dist\mingw64\bin\gcc.exe -c -w -fmax-errors=3 -mno-ms-bitfields -IC:\me\tools\nim-2.2.4\lib -IC:\Users\Administrator\temp\testpurenim -o C:\Users\Administrator\temp\testpurenim\gogo\@m..@s..@s..@s..@sme@[email protected]@slib@[email protected] C:\Users\Administrator\temp\testpurenim\gogo\@m..@s..@s..@s..@sme@[email protected]@slib@[email protected]
CC: ../../../../me/tools/nim-2.2.4/lib/std/private/digitsutils.nim: C:\me\tools\nim-2.2.4\dist\mingw64\bin\gcc.exe -c -w -fmax-errors=3 -mno-ms-bitfields -IC:\me\tools\nim-2.2.4\lib -IC:\Users\Administrator\temp\testpurenim -o C:\Users\Administrator\temp\testpurenim\gogo\@m..@s..@s..@s..@sme@[email protected]@slib@sstd@[email protected] C:\Users\Administrator\temp\testpurenim\gogo\@m..@s..@s..@s..@sme@[email protected]@slib@sstd@[email protected]
CC: ../../../../me/tools/nim-2.2.4/lib/system/dollars.nim: C:\me\tools\nim-2.2.4\dist\mingw64\bin\gcc.exe -c -w -fmax-errors=3 -mno-ms-bitfields -IC:\me\tools\nim-2.2.4\lib -IC:\Users\Administrator\temp\testpurenim -o C:\Users\Administrator\temp\testpurenim\gogo\@m..@s..@s..@s..@sme@[email protected]@slib@[email protected] C:\Users\Administrator\temp\testpurenim\gogo\@m..@s..@s..@s..@sme@[email protected]@slib@[email protected]
CC: ../../../../me/tools/nim-2.2.4/lib/std/syncio.nim: C:\me\tools\nim-2.2.4\dist\mingw64\bin\gcc.exe -c -w -fmax-errors=3 -mno-ms-bitfields -IC:\me\tools\nim-2.2.4\lib -IC:\Users\Administrator\temp\testpurenim -o C:\Users\Administrator\temp\testpurenim\gogo\@m..@s..@s..@s..@sme@[email protected]@slib@[email protected] C:\Users\Administrator\temp\testpurenim\gogo\@m..@s..@s..@s..@sme@[email protected]@slib@[email protected]
CC: ../../../../me/tools/nim-2.2.4/lib/system.nim: C:\me\tools\nim-2.2.4\dist\mingw64\bin\gcc.exe -c -w -fmax-errors=3 -mno-ms-bitfields -IC:\me\tools\nim-2.2.4\lib -IC:\Users\Administrator\temp\testpurenim -o C:\Users\Administrator\temp\testpurenim\gogo\@m..@s..@s..@s..@sme@[email protected]@[email protected] C:\Users\Administrator\temp\testpurenim\gogo\@m..@s..@s..@s..@sme@[email protected]@[email protected]
CC: xx.nim: C:\me\tools\nim-2.2.4\dist\mingw64\bin\gcc.exe -c -w -fmax-errors=3 -mno-ms-bitfields -IC:\me\tools\nim-2.2.4\lib -IC:\Users\Administrator\temp\testpurenim -o C:\Users\Administrator\temp\testpurenim\gogo\@mxx.nim.c.o C:\Users\Administrator\temp\testpurenim\gogo\@mxx.nim.c
Hint: ar rcs C:\Users\Administrator\temp\testpurenim\mylib.lib C:\Users\Administrator\temp\testpurenim\gogo\@m..@s..@s..@s..@sme@[email protected]@slib@[email protected] C:\Users\Administrator\temp\testpurenim\gogo\@m..@s..@s..@s..@sme@[email protected]@slib@sstd@[email protected] C:\Users\Administrator\temp\testpurenim\gogo\@m..@s..@s..@s..@sme@[email protected]@slib@[email protected] C:\Users\Administrator\temp\testpurenim\gogo\@m..@s..@s..@s..@sme@[email protected]@slib@[email protected] C:\Users\Administrator\temp\testpurenim\gogo\@m..@s..@s..@s..@sme@[email protected]@[email protected] C:\Users\Administrator\temp\testpurenim\gogo\@mxx.nim.c.o [Link]
Hint: mm: orc; threads: on; opt: none (DEBUG BUILD, `-d:release` generates faster code)
28715 lines; 1.099s; 31.141MiB peakmem; proj: C:\Users\Administrator\temp\testpurenim\xx.nim; out: C:\Users\Administrator\temp\testpurenim\mylib.lib [SuccessX]
PS C:\Users\Administrator\temp\testpurenim> cat .\xx.nim
# mylib.nim -------- 生成 Windows DLL 的最小示例
when defined(windows):
{.pragma: dllExport, cdecl, exportc, dynlib.}
else: # 其他平台去掉 dynlib 即可
{.pragma: dllExport, cdecl, exportc.}
proc add*(a, b: cint): cint {.dllExport.} =
a + b
PS C:\Users\Administrator\temp\testpurenim>
It seems you cannot change the command that is used to build static lib. https://github.com/nim-lang/Nim/blob/devel/compiler/extccomp.nim#L714
proc getLinkCmd(conf: ConfigRef; output: AbsoluteFile,
objfiles: string, isDllBuild: bool, removeStaticFile: bool): string =
if optGenStaticLib in conf.globalOptions:
if removeStaticFile:
removeFile output # fixes: bug #16947
result = CC[conf.cCompiler].buildLib % ["libfile", quoteShell(output),
"objfiles", objfiles,
"vccplatform", vccplatform(conf)]
else:
var linkerExe = getConfigVar(conf, conf.cCompiler, ".linkerexe")
if linkerExe.len == 0: linkerExe = getLinkerExe(conf, conf.cCompiler)
It loads linkerExe using getConfigVar but it takes the command to generate static lib from CC. CC is a const arrays contains commands, command line options or other C compiler specific infos and it is defined in extccom.nim.