Community
cancel
Showing results for 
Search instead for 
Did you mean: 
然_魏_
Beginner
338 Views

OpenCL example program(HelloWorld.cpp) cmake&make failed! CentOS 7

I download example code in “OpenCL Programming Guide” (by Aaftab Munshi…), but some error occurred while cmake .

——————————————————————————————————————————

[  OpenCL_Programming_Guide]# pwd

/home/OpenCL_Study/OpenCL_Programming_Guide

[  OpenCL_Programming_Guide]# cmake .

CMake Error at /usr/local/share/cmake-3.4/Modules/FindPackageHandleStandardArgs.cmake:148 (message):

  Could NOT find OpenCL (missing: OPENCL_LIBRARIES OPENCL_INCLUDE_DIRS)

Call Stack (most recent call first):

  /usr/local/share/cmake-3.4/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)

  cmake/FindOpenCL.cmake:80 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)

  CMakeLists.txt:9 (find_package)

 

 

-- Configuring incomplete, errors occurred!

See also "/home/OpenCL_Study/OpenCL_Programming_Guide/CMakeFiles/CMakeOutput.log".

[  OpenCL_Programming_Guide]# cmake .

CMake Error at /usr/local/share/cmake-3.4/Modules/FindPackageHandleStandardArgs.cmake:148 (message):

  Could NOT find OpenCL (missing: OPENCL_LIBRARIES OPENCL_INCLUDE_DIRS)

Call Stack (most recent call first):

  /usr/local/share/cmake-3.4/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)

  cmake/FindOpenCL.cmake:80 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)

  CMakeLists.txt:9 (find_package)

 

 

-- Configuring incomplete, errors occurred!

See also "/home/OpenCL_Study/OpenCL_Programming_Guide/CMakeFiles/CMakeOutput.log".

 

[  OpenCL_Programming_Guide]# echo $OPENCL_LIBRARIES

/opt/intel/opencl-1.2-sdk-5.0.0.93/lib64

[  OpenCL_Programming_Guide]# echo $OPENCL_INCLUDE_DIRS

/opt/intel/opencl/include/

——————————————————————————————————————————

 

Both OPENCL_LIBRARIES and OPENCL_INCLUDE_DIRS were set manually by me. (Not set by installed intel_code_builder_for_opencl_2015_5.0.0.62_x64)

 

However, I used cmake-gui to cmake is OK:

 

 

——————————————————————————————————————————

 

[OPG_output]# make

Scanning dependencies of target HelloWorld

[  8%] Building CXX object src/Chapter_2/HelloWorld/CMakeFiles/HelloWorld.dir/HelloWorld.cpp.o

/home/OpenCL_Study/OpenCL_Programming_Guide/src/Chapter_2/HelloWorld/HelloWorld.cpp: In function \u2018_cl_command_queue* CreateCommandQueue(cl_context, _cl_device_id**)\u2019:

/home/OpenCL_Study/OpenCL_Programming_Guide/src/Chapter_2/HelloWorld/HelloWorld.cpp:116:20: warning: \u2018_cl_command_queue* clCreateCommandQueue(cl_context, cl_device_id, cl_command_queue_properties, cl_int*)\u2019 is deprecated (declared at /opt/intel/opencl/include/CL/cl.h:1359) [-Wdeprecated-declarations]

     commandQueue = clCreateCommandQueue(context, devices[0], 0, NULL);

                    ^

/home/OpenCL_Study/OpenCL_Programming_Guide/src/Chapter_2/HelloWorld/HelloWorld.cpp:116:69: warning: \u2018_cl_command_queue* clCreateCommandQueue(cl_context, cl_device_id, cl_command_queue_properties, cl_int*)\u2019 is deprecated (declared at /opt/intel/opencl/include/CL/cl.h:1359) [-Wdeprecated-declarations]

     commandQueue = clCreateCommandQueue(context, devices[0], 0, NULL);

                                                                     ^

Linking CXX executable HelloWorld

CMakeFiles/HelloWorld.dir/HelloWorld.cpp.o: In function `CreateContext()':

HelloWorld.cpp:(.text+0x21): undefined reference to `clGetPlatformIDs'

HelloWorld.cpp:(.text+0xa2): undefined reference to `clCreateContextFromType'

HelloWorld.cpp:(.text+0xeb): undefined reference to `clCreateContextFromType'

CMakeFiles/HelloWorld.dir/HelloWorld.cpp.o: In function `CreateCommandQueue(_cl_context*, _cl_device_id**)':

HelloWorld.cpp:(.text+0x161): undefined reference to `clGetContextInfo'

HelloWorld.cpp:(.text+0x1f4): undefined reference to `clGetContextInfo'

HelloWorld.cpp:(.text+0x243): undefined reference to `clCreateCommandQueue'

CMakeFiles/HelloWorld.dir/HelloWorld.cpp.o: In function `CreateProgram(_cl_context*, _cl_device_id*, char const*)':

HelloWorld.cpp:(.text+0x3ac): undefined reference to `clCreateProgramWithSource'

HelloWorld.cpp:(.text+0x404): undefined reference to `clBuildProgram'

HelloWorld.cpp:(.text+0x43a): undefined reference to `clGetProgramBuildInfo'

HelloWorld.cpp:(.text+0x476): undefined reference to `clReleaseProgram'

CMakeFiles/HelloWorld.dir/HelloWorld.cpp.o: In function `CreateMemObjects(_cl_context*, _cl_mem**, float*, float*)':

HelloWorld.cpp:(.text+0x535): undefined reference to `clCreateBuffer'

HelloWorld.cpp:(.text+0x564): undefined reference to `clCreateBuffer'

HelloWorld.cpp:(.text+0x590): undefined reference to `clCreateBuffer'

CMakeFiles/HelloWorld.dir/HelloWorld.cpp.o: In function `Cleanup(_cl_context*, _cl_command_queue*, _cl_program*, _cl_kernel*, _cl_mem**)':

HelloWorld.cpp:(.text+0x64e): undefined reference to `clReleaseMemObject'

HelloWorld.cpp:(.text+0x66b): undefined reference to `clReleaseCommandQueue'

HelloWorld.cpp:(.text+0x67e): undefined reference to `clReleaseKernel'

HelloWorld.cpp:(.text+0x691): undefined reference to `clReleaseProgram'

HelloWorld.cpp:(.text+0x6a4): undefined reference to `clReleaseContext'

CMakeFiles/HelloWorld.dir/HelloWorld.cpp.o: In function `main':

HelloWorld.cpp:(.text+0x7dd): undefined reference to `clCreateKernel'

HelloWorld.cpp:(.text+0x8d8): undefined reference to `clSetKernelArg'

HelloWorld.cpp:(.text+0x8fc): undefined reference to `clSetKernelArg'

HelloWorld.cpp:(.text+0x920): undefined reference to `clSetKernelArg'

HelloWorld.cpp:(.text+0x9bf): undefined reference to `clEnqueueNDRangeKernel'

HelloWorld.cpp:(.text+0xa52): undefined reference to `clEnqueueReadBuffer'

collect2: error: ld returned 1 exit status

make[2]: *** [src/Chapter_2/HelloWorld/HelloWorld] Error 1

make[1]: *** [src/Chapter_2/HelloWorld/CMakeFiles/HelloWorld.dir/all] Error 2

make: *** [all] Error 2

[  OPG_output]#

——————————————————————————————————————————

 

It’s seemed that I still not configure environment correctly. Could you give me some advices?

 

Something you may want to know:

————————————————————————————————————————————

# find / -name libOpenCL.so*

 /opt/intel/opencl/libOpenCL.so.1

 /opt/intel/opencl/libOpenCL.so

 /opt/intel/opencl/libOpenCL.so.1.2

#

      8  Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz

00:02.0 VGA compatible controller [0300]: Intel Corporation Xeon E3-1200 v3/4th Gen Core Processor Integrated Graphics Controller [8086:0412] (rev 06)

————————————————————————————————————————————

0 Kudos
4 Replies
Robert_I_Intel
Employee
338 Views

When running cmake you can run it with -D options to specify the variables that you wish to define. Looks like you are not linking your executable correctly. Try to add /opt/intel/OpenCL/ to your LD_LIBRARY_PATH.

Could you also attach OpenCL_Programming_Guide.tar.gz to this thread so I can try to build it on my machine?

Thanks!

然_魏_
Beginner
338 Views

Robert Ioffe (Intel) wrote:

When running cmake you can run it with -D options to specify the variables that you wish to define. Looks like you are not linking your executable correctly. Try to add /opt/intel/OpenCL/ to your LD_LIBRARY_PATH.

Could you also attach OpenCL_Programming_Guide.tar.gz to this thread so I can try to build it on my machine?

Thanks!

Please forgive me I’m a beginner in cmake…

I have tried lots of ways but still made the mistake…..

 

Whether:

———————————————————————————————————

[root@storm108 OpenCL_Programming_Guide]# cmake -D OPENCL_INCLUDE_DIRS=/opt/intel/opencl/include/

CMake Error: The source directory "/home/OpenCL_Study/OpenCL_Programming_Guide/OPENCL_INCLUDE_DIRS=/opt/intel/opencl/include" does not exist.

———————————————————————————————————

 

Or

————————————————————————————————————

# This is an example project to show and test the usage of the FindOpenCL

# script.

 

cmake_minimum_required( VERSION 2.6 )

project( CL_Book )

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

find_package( OpenCL REQUIRED )

include_directories( ${OPENCL_INCLUDE_DIRS} )

include_directories( /opt/intel/opencl/include/ ) #I added

include_directories( "${CMAKE_SOURCE_DIR}/khronos" )

link_directories( /opt/intel/opencl-1.2-sdk-5.0.0.93/lib64 ) #I added

 

SUBDIRS(src)

————————————————————————————————————

Etc…

All of them don’t work…

What should I do, could you give me some suggestions?

(code please see atteched~↓)

 

 

Robert_I_Intel
Employee
338 Views

I was able to build with the following options

cmake -DOPENCL_INCLUDE_DIRS=/opt/intel/opencl/include -DOPENCL_LIBRARIES=/opt/intel/opencl/libOpenCL.so .

make

Note there are no spaces between -D and the variable it sets.

然_魏_
Beginner
338 Views

Robert Ioffe (Intel) wrote:

I was able to build with the following options

cmake -DOPENCL_INCLUDE_DIRS=/opt/intel/opencl/include -DOPENCL_LIBRARIES=/opt/intel/opencl/libOpenCL.so .

make

Note there are no spaces between -D and the variable it sets.

 

Great! it works! I really appreciate your help.

I think I should take cmake learning seriously...