A few notes on compilation of OpenCL codes on Mac OS X 10.6 with Nvidia GeForce 9400M




  • Preliminary steps:
  1. Install the CUDA Toolkit from here
  2. Install the drivers for your specific architecture (Mac OSX 10.6), and Graphic Card: using an Nvidia card, download them from here (Mac), or here (other architectures)

  • Compilation and linking:
Example of Makefile to compile the sample code for Vector Addition from Erik Smistad's blog (see below).
NOTE the linking: on a Mac you need to use "-framework OpenCL" instead of the "-I OpenCL" that would be used in Linux

For Linux compilation and runs see the Blog by Erik Smistad: link

#
# Simple makefile to compile the OpenCL main.c
# on a Mac OSX with linking to the OpenCL library installed
#
 
CC = gcc
LD = gcc -lm
 
CFLAGS = -Wall -shared
CDEBUG =
 
LIBOCL = -L/path/to/the/lib/folder/with/OpenCL/libfile/
INCOCL = -I/path/to/the/include/dir/with/cl.h/
 
SRCS = main.c
OBJS = main.o
 
EXE = vectorAddOCL.a
 
all: $(EXE)
 
$(OBJS): $(SRCS)
        $(CC) $(CFLAGS) $(INCOCL) -I/usr/include -c $(SRCS)
 
$(EXE): $(OBJS)
        $(LD) -L/usr/local/lib $(OBJS) $(LIBOCL) -o $(EXE) -framework OpenCL
 
clean:
        rm -f $(OBJS) *~
        clear

For my sepcific installation, I have the LIBOCL and INCOCL defined in the following:
#
# Simple makefile to compile the OpenCL main.c
# on a Mac OSX with linking to the OpenCL library installed
#
 
CC = gcc
LD = gcc -lm
 
CFLAGS = -Wall -shared
CDEBUG =
 
LIBOCL = -L/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/OpenCL.framework/Versions/A/Libraries
INCOCL = -I/System/Library/Frameworks/OpenCL.framework/Versions/A/Headers
 
SRCS = main.c
OBJS = main.o
 
EXE = vectorAddOCL.a
 
all: $(EXE)
 
$(OBJS): $(SRCS)
        $(CC) $(CFLAGS) $(INCOCL) -I/usr/include -c $(SRCS)
 
$(EXE): $(OBJS)
        $(LD) -L/usr/local/lib $(OBJS) $(LIBOCL) -o $(EXE) -framework OpenCL
 
clean:
        rm -f $(OBJS) *~
        clear