Getting started on MacOs X 10.6

Hi alltogether,

as I am writing to this board I am quite new to programming with OpenCL - I recently made some attempts to get some C++ sample Code from the tutorials compiled under MacOS X SnowLeopard but unfortunatetly none of them succeeded.

The main problem is that the normal way to include the openCL framework headers which is described in the tutorials (use #include OpenCL/opencl.h) does not work on my system.
The only place the header files are located is /System/Library/Frameworks/OpenCL.framework/Versions/A/Headers/ which is not in the search path assumed - I tried to fix that by switching
to the commandline interface , using the -I and -L switches in combination with the “-framework opencl” option - but this did not work either. The error message always follows the pattern:
firstCL.cpp: In function ‘int main()’:
firstCL.cpp:28: error: ‘cl’ has not been declared
firstCL.cpp:28: error: ‘cl’ has not been declared
firstCL.cpp:28: error: ‘platformList’ was not declared in this scope
firstCL.cpp:29: error: ‘Platform’ has not been declared
firstCL.cpp:39: error: ‘cl’ has not been declared
firstCL.cpp:39: error: expected `;’ before ‘context’
firstCL.cpp:46: error: ‘cl’ has not been declared
firstCL.cpp:46: error: ‘cl’ has not been declared
firstCL.cpp:46: error: ‘devices’ was not declared in this scope
firstCL.cpp:47: error: ‘context’ was not declared in this scope

what in my interpretation means that the cl:: namespace qualifier is not found in that context

Did anybody run into the same problem and can give me some guidance how to proceed from here.
Do I ,for example, have to install a certain package - c++ bindings ?
the code I am using for testing follows below.

Best regards + many thanks in advance

#include <stdlib.h>
#include <math.h>
#include <OpenCL/opencl.h>

int main (int argc, const char * argv[]) {

// some code

cl_device_id device_id; //declaring a device id gives no errors

int err = clGetDeviceIDs(NULL, CL_DEVICE_TYPE_GPU, 1, &device_id, NULL);

// insert code here...
printf("Hello, World!

printf(“Device ID is : %s”, device_id);
printf(” err is %d", err);

return 0;


#include <utility>

#define __NO_STD_VECTOR // Use cl::vector instead of STL version
#include <OpenCL/opencl.h>

#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <string>
#include <iterator>

const std::string hw("Hello World

inline void
checkErr(cl_int err, const char * name)
if (err != CL_SUCCESS) {
std::cerr << “ERROR: " << name
<< " (” << err << “)” << std::endl;
cl_int err;
vector< cl::Platform > platformList;
checkErr(platformList.size()!=0 ? CL_SUCCESS : -1, “cl::Platform::get”);
std::cerr << "Platform number is: " << platformList.size() << std::endl;

std::string platformVendor;
platformList[0].getInfo((cl_platform_info)CL_PLATFORM_VENDOR, &platformVendor);
std::cerr &lt;&lt; "Platform is by: " &lt;&lt; platformVendor &lt;&lt; "

cl_context_properties cprops[3] =
{CL_CONTEXT_PLATFORM, (cl_context_properties)(platformList[0])(), 0};

cl::Context context(
checkErr(err, "Conext::Context()");
cl::vector&lt;cl::Device&gt; devices;
devices = context.getInfo&lt;CL_CONTEXT_DEVICES&gt;();
		 devices.size() &gt; 0 ? CL_SUCCESS : -1, "devices.size() &gt; 0");
std::ifstream file("");
checkErr(file.is_open() ? CL_SUCCESS:-1, "");

std::string prog(

cl::Program::Sources source(
							std::make_pair(prog.c_str(), prog.length()+1));

cl::Program program(context, source);
err =,"");
checkErr(file.is_open() ? CL_SUCCESS : -1, "Program::build()");
cl::Kernel kernel(program, "hello", &err);
checkErr(err, "Kernel::Kernel()");

err = kernel.setArg(0, outCL);
checkErr(err, "Kernel::setArg()");
cl::CommandQueue queue(context, devices[0], 0, &err);
checkErr(err, "CommandQueue::CommandQueue()");

cl::Event event;
err = queue.enqueueNDRangeKernel(
								 cl::NDRange(1, 1),
checkErr(err, "ComamndQueue::enqueueNDRangeKernel()");
err = queue.enqueueReadBuffer(
checkErr(err, "ComamndQueue::enqueueReadBuffer()");
std::cout &lt;&lt; outH;


#pragma OPENCL EXTENSION cl_khr_byte_addressable_store : enable
__constant char hw[] = "Hello World
__kernel void hello(__global char * out)
size_t tid = get_global_id(0);
out[tid] = hw[tid];

The framework header file OpenCL/opencl.h includes the OpenCL 1.0 Khronos C language headers. The source code posted above appears to use C++ wrappers which are not part of the OpenCL framework in SnowLeopard.

HI Board,

after some months of absence I am returning to the topic - it its somewhat strange - that I could not find any tutorial on how to install OpenCL correctly on MacOS X 10.6 - I guess most of the board members who have it up and running have done something different or have a different (Developer) Version of MacOS - (My MacBook Pro runs on Mac OS X 10.6.6 (10J567) ) I am writing this because in contrary to what I am reading on the topic on my System (for example) the directory /System/Library/Frameworks/OpenCL.framework does not exist (and a search with “find” or the Finder does not return a positive result) - and that after I went trough the complete install process of the Developers DVD at least 2 times. And this (please correct me if I am wrong ) seems to be essential to make development with OpenCL possible.

My concluding question is: what needs to be done to get a MacOs X 10.6 ready to compile OpenCL code - are there additional repositories of OpenCL.framework - which are not part of the Apple distribution - do other images / version of the Apple Developers DVD which are proven/known to come with OpenCL.framework . (If so please give me a link)

Best regards + Many thanks in advance
Stefan :?: :?: :?:

Back in the day all I did was dowload and install XCode. Everything worked out of the box.

Ok. - Many Thanks David for your reply !,

after my reinstall i finally got OpenCL installed on my box (That is the OpenCL C Examples from the Apple Developers Page run without problems) - the bad news is that I still have trouble to compile programs that use the C++ Bindings - What I have done up to now is that I downloaded the cl.hpp file from Khronos and copied into the directories /System/Library/Frameworks/OpenCl.framework/Headers and /Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/OpenCL.framework/Versions/A/Headers/cl.hpp

Sadly I found that this is not working as expected - I got “file not found” - (in Xcode)
After trying this I also copied the cl.hpp file into the sources directories of my examples from various tutorials I found in the web - the result is that I got a clean compile on the command line - and a runtime error
“clBuildProgram(-11)” while trying to run the binary - and in Xcode no parse errors but 24 linking errors - one for every OpenCL c++ binding used in the example code.

looks like this:

Ld build/Debug/OpenCLTest3 normal x86_64
cd /Users/steve/Documents/OpenCLTest3
/Developer/usr/bin/g+±4.2 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -L/Users/steve/Documents/OpenCLTest3/build/Debug -F/Users/steve/Documents/OpenCLTest3/build/Debug -filelist /Users/steve/Documents/OpenCLTest3/build/ -mmacosx-version-min=10.6 -o /Users/steve/Documents/OpenCLTest3/build/Debug/OpenCLTest3

Undefined symbols:
“_clCreateKernel”, referenced from:
cl::Kernel::Kernel(cl::Program const&, char const*, int*)in OpenCLTest3.o
“_clRetainMemObject”, referenced from:
cl::detail::ReferenceHandler<_cl_mem*>::retain(_cl_mem*)in OpenCLTest3.o
“_clWaitForEvents”, referenced from:
cl::Event::wait() constin OpenCLTest3.o
“_clReleaseKernel”, referenced from:
cl::detail::ReferenceHandler<_cl_kernel*>::release(_cl_kernel*)in OpenCLTest3.o
“_clGetProgramBuildInfo”, referenced from:
int cl::Program::getBuildInfo<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >(cl::Device const&, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> >) constin OpenCLTest3.o
“_clCreateCommandQueue”, referenced from:
cl::CommandQueue::CommandQueue(cl::Context const&, cl::Device const&, unsigned long long, int
)in OpenCLTest3.o
“_clCreateBuffer”, referenced from:
cl::Buffer::Buffer(cl::Context const&, unsigned long long, unsigned long, void*, int*)in

etc. etc.

As I understand the issue ld does not find the library which is referenced by the cl.hpp wrapper - and I up to now have no idea which of the libs that come with OpenCL I should take - I already tried to give ld a hint by adding the option -L /System/Library/Frameworks/OpenCl.framework/Libraries to my commandline - but this did not change anything.

Any more ideas ? - what’s wrong with my build environment ?

Thank you in advance
Best regards

Did you add the OpenCL framework to your XCode project? That’s all you should need to do. Try following a simple tutorial on XCode and OpenCL, such as this.

Hi David,

yes I did - that’ how I have got my code examples - the presentation you gave me the link on lacks hints on my concrete problem - C++ is only referenced to in the sense that OpenCL is not designed to support true (memory) objects - but that is what the wrapper (C++ Bindings) is for - interfacing between C Objects and C++ Class Definitions. But the C++ Bindings and XCode are not subject of the presentation. As I told you in my previous post I followed the tutorials and copied the cl.hpp in the directories where the tutorials say they should be found - what makes it hard to find a resolution to the resulting errors is that all of the tutorials are written by guys that work for AMD or use the AMD Implementation or have a Mac what seems to make them assuming that everything is working right out of the box - and therefore aren’t bothering any more the setup of Xcode etc. If you have an Idea what steps are necessary to make Xcode aware of the C++ Bindings please tell me

  • What puzzles me in that case is that OpenCL C works - and if I copy the cl.hpp header in the source directory becomes involved in the compiler-run but the linker fails to get the references straight - strange because it’s a hpp and therefore no additional library is needed to link the implementation is already in the header file - it might be the case that Xcode takes the cl.hpp for a mere header and therefore does not compile binary code out of it - but I have switched to XCode for this project and up to now have not found any menu options that allow to modify the build environment like it is possible in eclipse.

So Again - Is there a way to make Xcode aware of cl.hpp in the correct manner (compiling the implementation into the binary and linking correctly) -As I read somewhere without giving noticeto it too much is that there is a switch that enables(or disables) compiling .hpp files in Xcode - actually I cannot find this switch - but it might be a hint. (Any suggestions ?)

Thanks in advance
Best Regards

I don’t have a mac, so I’m taking a stab here - but make sure that you are using the right OpenCL version (1.0 vs 1.1). If you are attempting to use the 1.1 .hpp file, and your OpenCL version on your mac is 1.0, would that cause problems?

Hi General,
thanks for your post but as indicated on the Khronos API Registry page the header cl.hpp works for both - 1.0 and 1.1 -I made the test with diff - both links on the page point to the same file.

Best regards

The undefined symbol errors above suggest that the project doesn’t include the OpenCL.framework. Here are the steps to get started with the C++ bindings in Xcode3:

1.) Open XCode3
2.) File -> New Project; select Application -> Command Line Tool; select Type: C++
3.) Save the project ‘Untitled’ somewhere
4.) Expand Targets; right click on ‘Untitled’ -> Add -> Existing Frameworks
5.) Scroll down and select OpenCL.framework; click Add
6.) Open Safari and navigate to cl.hpp on; File -> Save As; place the file in the ‘Untitled’ project folder (same directory as main.cpp).
7.) Right click on ‘Untitled’ project; -> Add -> Existing Files; Select ‘cl.hpp’ from the project folder.
8.) Edit main.cpp. Add #include “cl.hpp”. In the main() function, add some C++ bindings test code.
9.) Build -> Build and Run.

If you aren’t using the optional C++ bindings then only steps 1-5 are needed (plus including <OpenCL/opencl.h> instead of “cl.hpp”). If you work outside of Xcode, e.g. using Makefiles, use the flag “-framework OpenCL” to link with the framework and include its headers.

Yeah - adding the framework in targets did the trick ! ajs2 you made my day !

Many Thanks !
Best Regards


thanks ajs2 from another newb on a mac