Friday, May 13, 2016

C programming using cmd.exe

Windows provides you command line tools when you install VisualStudio Community 2015 (VS2015). You can use VS2015 up to 30 days trial, and after that you'll get prompt asking you to get license, but you still can use the command line tools.

To compile a C program, VS2015 provides you a command line intepreter called cl. To use it, you need to setup the development environment. Luckily, VS2015 also provides a batch script to do this for you. The script is called VsDevCmd.bat and is located inside <VS2015 installation folder>\Common7\Tools.

The most basic usage of cl is:
cl your_first_program.c

If you wish to add extra libraries, you need to append the %INCLUDE% and %LIB% variables. To do this just use the SET command. For example, if you want to include Python.h, you do the following:
SET LIB=%LIB%%PYTHON_HOME%\libs;
SET INCLUDE=%INCLUDE%%PYTHON_HOME%\include;