How do I that? I don't want to use the Visual Studio IDE, yet I want to use the provided compiler (cl.exe) and the Developer Command Prompt for VS2013.
Asked
Active
Viewed 2,714 times
3 Answers
5
I used to do it to via command line
cl /EHsc /MD main.cpp /Fetest.exe /I F:\C++_Libraries\SDL2\SDL2-2.0.3\include /link /LIBPATH:F:\C++_Libraries\SDL2\SDL2-2.0.3\lib\x86 SDL2.lib SDL2main.lib /SUBSYSTEM:CONSOLE

CroCo
- 5,531
- 9
- 56
- 88
-
1`/SUBSYSTEM:WINDOWS` works as an alternative to `/SUBSYSTEM:CONSOLE` if you don't want console output. – Tom Palmer Jul 09 '18 at 13:41
2
cl.exe /Wall /Tc main.c
will generate a proper main.exe
.
and before that:
- ensure that c:\Windows\System32 is in the PATH
- execute
vcvarsall.bat
from your install directory of VC
If you want to use a library (e.g., SDL) you need to list the libraries with /link
option (library paths can be added with /LIBPATH
) and the library include directories with /I
option.

ouah
- 142,963
- 15
- 272
- 331
-
Thanks! Also, maybe I won't need to execute the .bat file, since the Developer Command Prompt sets up the environment variables for me, right? Thanks again. – Fernando Karpinski May 11 '15 at 22:44
-
@FernandoKarpinski I don't know the Developer Command Prompt, but I think it's a fair assumption. – ouah May 11 '15 at 23:00
2
I faced this problem as well. I had to do two things to fix it:
- Add the
/SUBSYSTEM:CONSOLE
as mentioned in previous answers. Note that this gives a different error along the lines oferror LNK2019: unresolved external symbol __imp_CommandLineToArgvW referenced in function main_getcmdline
. This can be solved with doing the next step. - Link the
Shell32.lib
as mentioned in the SDL forums: https://discourse.libsdl.org/t/windows-build-fails-with-missing-symbol-imp-commandlinetoargvw/27256/2
So my final command line command looks like:
cl.exe /Zi /I "C:\...\SDL2-2.0.12\include" sdl_program.c /link "C:\...\lib\x64\SDL2main.lib" "C:\...\lib\x64\SDL2.lib" "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.18362.0\um\x64\shell32.lib" /SUBSYSTEM:CONSOLE

Dharman
- 30,962
- 25
- 85
- 135

Samarth Hattangady
- 696
- 1
- 7
- 10