7

I'm on OS X 10.7 Lion and have all the dev tools installed, but when I run GCC on a relatively simple program, just straight C with a few calls to openCL functions like clCreateProgramFromSource and the like, I get the following list of errors:

Undefined symbols for architecture x86_64:
  "_CreateContext", referenced from:
    _build_kernel in ccFuZYMI.o
  "_GetDevices", referenced from:
    _build_kernel in ccFuZYMI.o
  "_CreateCommandQueue", referenced from:
    _build_kernel in ccFuZYMI.o
  "_clCreateProgramWithSource", referenced from:
    _build_kernel in ccFuZYMI.o
  "_clBuildProgram", referenced from:
    _build_kernel in ccFuZYMI.o
  "_clCreateKernel", referenced from:
    _build_kernel in ccFuZYMI.o
  "_clCreateBuffer", referenced from:
    _build_kernel in ccFuZYMI.o
  "_clEnqueueWriteBuffer", referenced from:
    _sync_run_kernel in ccFuZYMI.o
  "_clSetKernelArg", referenced from:
    _sync_run_kernel in ccFuZYMI.o
  "_clEnqueueNDRangeKernel", referenced from:
    _sync_run_kernel in ccFuZYMI.o
  "_clEnqueueReadBuffer", referenced from:
    _sync_run_kernel in ccFuZYMI.o
  "_clReleaseContext", referenced from:
    _destroy_kernel in ccFuZYMI.o
  "_clReleaseCommandQueue", referenced from:
    _destroy_kernel in ccFuZYMI.o
  "_clReleaseMemObject", referenced from:
    _destroy_kernel in ccFuZYMI.o
  "_clReleaseProgram", referenced from:
    _destroy_kernel in ccFuZYMI.o
  "_clReleaseKernel", referenced from:
    _destroy_kernel in ccFuZYMI.o
ld: symbol(s) not found for architecture x86_64

There are some other warnings, but no other errors at compulation stage. This is (in case not clear) a linker error. It seems to be able to see the definitions from the header file while creating the object file, because it gives me warnings about incompatible pointer types.

I have tried pasting into an xcode project, but I get exactly the same errors. I have tried the only other OS X Lion / OpenCL result's solution, and it didn't help.

Community
  • 1
  • 1
tehwalrus
  • 2,589
  • 5
  • 26
  • 33
  • possible duplicate of [How can I compile Open CL on Mac OS X 10.6.3?](http://stackoverflow.com/questions/2725982/how-can-i-compile-open-cl-on-mac-os-x-10-6-3) – Paul R Oct 05 '11 at 15:38
  • I had the same issue and I resolved it by adding the existing OpenCL framework in my Mac. I referred to think link - http://stackoverflow.com/questions/3352664/how-to-add-existing-frameworks-in-xcode-4 – Raghav Feb 11 '15 at 08:31
  • I wondered why can't apple just let it be a library under -lopengl – Dendi Suhubdy Mar 24 '16 at 16:28

2 Answers2

16

Looks like you're missing the OpenCL framework - try:

$ gcc -Wall foo.c -framework OpenCL -o foo
Paul R
  • 208,748
  • 37
  • 389
  • 560
  • 1
    indeed, this is the problem. foolish! I still have a few missing symbols, but it looks like they're shortcuts that only exist in NVidia online samples. Thanks! – tehwalrus Oct 05 '11 at 15:40
3

It looks to me like you're not linking against the OpenCL libraries. Can you post the link command that you are trying to use? Without that information, simply shooting from the hip: add -framework OpenCL.

Stephen Canon
  • 103,815
  • 19
  • 183
  • 269
  • thanks very much, you also are correct! Alas, Paul R gets the correct answer since he was (very slightly) quicker. :) – tehwalrus Oct 05 '11 at 15:41