Anthony Edward Maylath
Anthony Edward Maylath

Reputation: 102

Compile OpenCL HelloWorld Program: Linker Error

My Reference code was taken from "OpenCL Programming Guide" by Aaftab Munshi. The source files for the code can be found at https://github.com/bgaster/opencl-book-samples/tree/master/src/Chapter_2/HelloWorld

I am attempting to run the code on macOS Sierra, Version 10.12.6. Following the instructions in the book, I run the following commands in the folder containing the source files found at the above GitHub link:

mkdir build
cd build
cmake ../ "CodeBlocks - Unix Makefiles"

You need to have cmake installed for the last line to run. The example comes from Chapter 2, pg. 41 of the text. Running the cmake generates a Code::Blocks file. When I try to build the Code::Blocks file, I get the following error:

ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [HelloWorld] Error 1
make[1]: *** [CMakeFiles/HelloWorld.dir/all] Error 2
make: *** [all] Error 2 

Would anyone know why this error occurs? It seems to be an issue with the build process and not the C syntax.

Thank you!

Upvotes: 1

Views: 430

Answers (2)

Tsyvarev
Tsyvarev

Reputation: 65928

Instruction installations specifically says, that you should build the entire project (pass to cmake a source directory equal to top-level directory of the cloned project).

CMakeLists.txt, contained in each example, cannot be built separately.

(Look, they miss cmake_minimum_required() and project() calls, needed by every CMake project; call to find_project(OpenCL), which would set variable OPENCL_LIBRARIES, is missed too).

Upvotes: 0

Richard Barber
Richard Barber

Reputation: 6431

To get cmake to see mac openCL stuff for the LuminanceHDR/opencl branch, I had to do the following (add to CMakeLists.txt):

# find OpenCL on Mac
find_package(OpenCL REQUIRED)
include_directories(SYSTEM ${OpenCL_INCLUDE_DIRS})
SET(LIBS ${LIBS} ${OPENCL_Libraries})
SET(CMAKE_EXE_LINKER_FLAGS "-framework OpenCL -rpath @loader_path/../Frameworks/")

Upvotes: 1

Related Questions