Using the Windows SDK Tools to Compile Against SpinCore Libraries

SpinCore Technologies, Inc.

November 19, 2013 1 Introduction

Recently, SpinAPI’s compilation process has moved to the SDK C/C++ compiler. The reason behind this move away from GCC is that true 64bit support became necessary. In order to use GCC for 64bit compilation on Windows, plain MinGW is not enough; a Cygwin environment with a 64bit port of MinGW becomes necessary. Requiring the use of Cygwin not only complicates the compilation process for us, but for customers as well. The current solution to this problem is to use the Microsoft Windows SDK C/C++ compiler. The SDK provides an easy way to setup the correct build environment for 64bit or 32bit, and also will use the correct C++ name mangling conventions for C++ libraries compiled with Visual Studio. Additionally, the compilation method is easily scriptable.

2 Install necessary Tools

The Microsoft Windows SDK (at least v7.1 is recommended) is required to compile C programs against the SpinAPI , or other SpinCore API packages. The Windows SDK can be found for free on Microsoft’s MSDN website.

3 Setup Build Environment

The Microsoft Windows SDK comes with a tool called “setenv.cmd”. This is the tool that is used to setup the 64bit and 32bit build environments. It is found in the installation directory of the SDK under the “Bin” folder. If you would like to have this tool available at the command line without typing out the absolute path, you will need to add the “Bin” directory to the system’s path variable. This can be done as follows (on ): 1. Click on the “Start” menu. 2. Right click on “Computer” 3. Click “Properties”

4. Click “Advanced System Settings” 5. Click “Environment Variables” 6. Under “System Variables” click on “Path”, then click the “Edit...” button below.

7. Add a semicolon at the end of the “Variable value” field, and then enter the full path to where “setenv.cmd” resides, for example (without quotes): “C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin” 8. Press “OK” 3 times. Now you will be able to open a terminal and have “setenv.cmd” available in the system path.

3.1 Usage of “setenv.cmd” To set up a 64bit build environment: setenv.cmd /x64 /release

To set up a 32bit build environment: setenv.cmd /x86 /release

1 4 Compiling

Once “setenv.cmd” has been called, the proper build environment has been setup and the compilers are available. “cl.exe” is the C/C++ compiler used. Some important parameters are listed below. • Adding Include Directories:

cl.exe foo.c /I YourPath

• Linking against a library requires that you add a full or relative path to the .lib file.

cl.exe foo.c \path\to\bar.lib

Full example of 64bit compilation (with SpinAPI 64bit): cd C:\SpinCore\Examples\General setenv.cmd /x64 /release cl.exe .\read_firmware.c /IC:\SpinCore\SpinAPI\inc C:\SpinCore\SpinAPI\lib\spinapi64.lib

Full example of 32bit compilation (with SpinAPI 32bit): cd C:\SpinCore\Examples\General setenv.cmd /x86 /release cl.exe .\read_firmware.c /IC:\SpinCore\SpinAPI\inc C:\SpinCore\SpinAPI\lib\spinapi.lib

Full example of 32bit compilation (with SpinAPI 64bit): cd C:\SpinCore\Examples\General setenv.cmd /x86 /release cl.exe .\read_firmware.c /IC:\SpinCore\SpinAPI\inc C:\SpinCore\SpinAPI\lib32\spinapi.lib

2 Revisions Version Description Author Date 1.0 Initial document creation Patrick Gauvin 20121220 1.1 Revised to reflect new directory structure of SpinAPI Patrick Gauvin 20131119

3