Does anyone have a working nim.cfg for Visual Studio 2015 (2013 onwards?)
The default vcc settings are for vccexe.exe rather than cl.exe and the "--platform" parameter is invalid for cl.exe
Answering my own question:
# Configuration for the MS Visual Studio C/C++ compiler:
vcc.exe = "cl.exe"
vcc.linkerexe = "cl.exe"
# set the options for specific platforms:
vcc.options.always = "/nologo /EHsc"
vcc.options.linker = "/nologo /Zi /F33554432" # set the stack size to 32 MiB
vcc.options.debug = "/Zi /FS /Od /GZ /Ge"
vcc.options.speed = "/O2"
vcc.options.size = "/O1"
(so didn't require /DEBUG /link --platform and needed /EHsc)
Prior to running nim at the command line, I need to run one of (and depends on whether on an x86 or amd64 system)
For cross compiling, I need to run the vcvarsxxxx.bat file from the appropriate directory first
2. Use this line in vccnim.cmd (adjust path to match your installation): > @call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
nim.exe %*
I've read that %* doesn't handle quoted parameters, so if someone has a better solution, please tell us.
@Araq I did not even tried the default config, after reading this post; I assumed it didn't work... I'll try it asap.
EDIT: I cannot get the default configuration to work for me either.
(Initially, cl.exe isn't in my default path)
If I run vccexe.exe I get the following
"C:\Windows\system32\cmd.exe" /C "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall && SET"
cl.exe
Traceback (most recent call last)
vccexe.nim(61) vccexe
osproc.nim(581) startProcess
oserr.nim(113) raiseOSError
Error: unhandled exception: The system cannot find the file specified.
Additional info: Requested command not found: 'cl.exe'. OS error: [OSError]
However, if I then run the vcvarsall manually from the command prompt, it will set the various environment variables
and cl.exe can now run from the command line, and NOW vccexe.exe works
and nim c --cc:vcc -r ... works
Note: the C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall needs to be quoted to allow for the spaces in the command (yeah, the joys of windows)
The compilation should now work as expected.
I want to point out that nowhere online did I find this solution posted.
Hope this helps someone else in the future.
If you want Nim to C/C++ compiler in MS visualstudio, just call nim with --cc:vcc option. If you want to see how Nim call cl.exe, add --listcmd option.
For example:
nim c --cc:vcc --listcmd test.nim
If you want Nim always use cl.exe, add cc = vcc in nim.cfg. And put the cfg file in %APPDATA%/nim/nim.cfg. If you want to use cl.exe in specific nim file, put the nim.cfg in the same directory. (Detail of how Nim process configuration files: https://nim-lang.org/docs/nimc.html#compiler-usage-configuration-files)
I don't think it is a good idea to edit C:\nim\config\nim.cfg or nim.cfg in Nim install directory. When you update your Nim, that file is also replaced by new one.
@AmbrusFernas I don't understand what you are trying, but if you just want to use Nim on windows, you can install Nim using choosenim. https://github.com/dom96/choosenim It also install mingw32 as backend C compiler.