Continuing our blog series "<a href="http://sandbox.arrayfire.com/tag/learning-arrayfire-from-scratch/">Learning ArrayFire from scratch</a>" today we will discuss how to set up an ArrayFire project on Windows using Microsoft Visual Studio 2013.

If you haven't already, please download and install ArrayFire from our <a href="http://sandbox.arrayfire.com/download">downloads page</a>.

This blog is divided into 2 parts. The first part deals with a simple way for you to add a single ArrayFire backend to your existing project. The second part deals creating an ArrayFire project from scratch that can use all the backends by simply switching the configuration.

<h4>Part 1: Adding ArrayFire to your existing project</h4>
There are 3 main steps to adding ArrayFire to your project.

<h5>1. Add ArrayFire Include Directory</h5>
Open Project Properties -> C/C++ -> General -> Additional Include Directories and append "$(AF_PATH)/include;".

<h5>2. Add ArrayFire Library and Directory</h5>
Open Project Properties -> Linker -> General -> Additional Library Directories and append "$(AF_PATH)/lib;".
Open Project Properties -> Linker -> Input -> Additional Dependencies and append "afbackend.lib", where backend should be replaced with cpu/cuda/opencl.

<h5>3. Add Helper Definitions (Optional)</h5>
Open Project Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions and append "NOMINMAX;AF_BACKEND", where you can replace BACKEND with CPU/CUDA/OPENCL.
The NOMINMAX definition is recommended.

<h5>X. Copy CUDA DLLs</h5>
If you choose to use the CUDA backend in your project, you will need to copy the NVVM DLL to a suitable location. This DLL is not a part of the standard PATH and hence can result in runtime errors if not copied. We recommend copying this to the executable directory. To make this process automatic, we can add this as a post build command so that it runs with every build.

Open Project Properties -> Build Events -> Post Build Events (click edit). In the dialog box, enter
<pre>
echo copy "$(CUDA_PATH)\nvvm\bin\nvvm64*.dll" "$(OutDir)"
copy "$(CUDA_PATH)\nvvm\bin\nvvm64*.dll" "$(OutDir)"
</pre>
Note: Ensure the new line in between.

<!--more-->

&nbsp;