Something More for Research

Explorer of Research #HEMBAD

Configuring Your First OpenCL Project

Posted by Hemprasad Y. Badgujar on October 16, 2012



To actually use OpenCL you’ll need to tell Visual Studio where to find the OpenCL libraries and functions.

First thing we need to do is create a new ‘Empty Project’ in Visual Studio.

Name this project whatever you want but leave the other options as default. Visual Studio will make a new solution for your project and create a new folder to keep your files in. For this article, I’ve named my new project ‘opencl_test’.

With your new empty project created it’s time to tweak the project settings so that your editor knows where to find OpenCL.

Go in to ‘Projects->opencl_test Properties’  and you’ll get your project’s configuration page. The first thing we need to do is change the Configuration that we’re editing. By default, mine is set to Active(Debug). We want to set it to “All Configurations”.

Next we need to find the Additional Include Directories option. (note that ‘opencl_test Properties’ will be different for you if you named your project something else.)

Double-click on the C/C++ menu to expand it and expose the C/C++ sub-menus. Click on General. Now you’ll see the Additional Include Directories option at the top of the right window.

Simply type in the environment variable “$(CUDA_INC_PATH)”. It will point to the actual include directory to wherever the CUDA Toolkit was installed to.

You should now have your settings looking like this:

Now that Visual Studio knows where to find our files, we need to tell it to use those files when compiling our program.

With the Properties page still open, double-click on Linker then on General. In the right window, there will be an option called ‘Additional Library Directories’. This is where we’re going to tell the linker where the libraries for the OpenCL functions are. Think of it like OpenCL’s “guts”.

Again, we’re going to type in the environment variable which points to the library directory for the CUDA Toolkit. In this case, we want to type in “$(CUDA_LIB_PATH)”. This will automatically use the lib folder from the CUDA Toolkit’s install path for us.

When all is said and done, you should look like this:

Referencing proper OpenCL libraries in Visual Studio

Now that Visual Studio knows where to find the library files, we need to tell it which library file to actually use. To do this, we’re going to take a peak at the Input sub-menu under Linker. Click that, and in the right window you’ll see an option called ‘Additional Dependencies’. All you need to do here is enter in ‘opencl.lib’ without the quotes.

For the visual learners out there, here’s what we should be looking at right now:

Linking OpenCL In Visual Studio 2008

Click Apply to apply the changes to the linker settings for your project. Now let’s test these settings to make sure you’ve configured your project correctly and that Visual Studio can find and use the OpenCL files.

To test our project settings, we’re going to make a quick and simple C file that includes the OpenCL header file and uses an OpenCL library function. If you missed a step somewhere, the compiler will spit out some errors at you.

Make a new file. Call it “main.c”. Paste the following in main.c:

#include “CL/cl.h”

int main(int argc, char **argv){
cl_platform_id test;
cl_uint num;
cl_uint ok = 1;
clGetPlatformIDs(ok, &test, &num);

return 0;

Try to compile now. If all is well, you’ll get 0 warnings and 0 errors (depending on your warning settings, which I didn’t cover, you may get two warnings about argc and argv. You can safely ignore those.)

Now, don’t get the wrong impression here. I am not the type of person to tell somebody to just paste some code and compile. You won’t learn that way and I’m here to help you learn. I will explain what’s going on in the next tutorial and don’t want to be redundant in my articles. This is why I choose to simply have you paste this code in main.c to test your configuration.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Extracts from a Personal Diary

dedicated to the life of a silent girl who eventually learnt to open up

Num3ri v 2.0

I miei numeri - seconda versione


Just another site

Algunos Intereses de Abraham Zamudio Chauca

Matematica, Linux , Programacion Serial , Programacion Paralela (CPU - GPU) , Cluster de Computadores , Software Cientifico




A great site

Travel tips

Travel tips

Experience the real life.....!!!

Shurwaat achi honi chahiye ...

Ronzii's Blog

Just your average geek's blog

Karan Jitendra Thakkar

Everything I think. Everything I do. Right here.


News About Tech, Money and Innovation

Chetan Solanki

Helpful to u, if u need it.....


Explorer of Research #HEMBAD


Explorer of Research #HEMBAD


A great site


This is My Space so Dont Mess With IT !!

%d bloggers like this: