Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could NOT find OpenCL (missing: OpenCL_LIBRARY)

Tags:

cmake

opencl

I'm trying to use OpenCL with CLion (specifically boost compute), using CMake, on windows 10 with nvidia gpu. It feels like I have tried everything, but I have no idea how CMake works, and I cannot find a basic enough post on the web for me to understand. The official documentation isn't that helpful to a beginner either. I also need to eventually get this running on OS X and some flavour of Linux.

This is the mess I'm in (CmakeLists.txt):

cmake_minimum_required(VERSION 3.3)
project(cpl)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2")

set(SOURCE_FILES
        src/planner/main.cpp)

set(BOOST_ROOT C:/boost)
set(BOOSTROOT C:/boost)

include_directories(lib/compute/include)

include_directories($ENV{CUDA_PATH})

# boost
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.60.0 REQUIRED)

# opencl
set(CMAKE_MODULE_PATH lib/cmake)

find_package(OpenCL REQUIRED)

INCLUDE_DIRECTORIES(${OpenCL_INCLUDE_DIRS})

LINK_DIRECTORIES(${OpenCL_LIBRARY})

message(STATUS "OpenCL found: ${OPENCL_FOUND}")
message(STATUS "OpenCL includes: ${OPENCL_INCLUDE_DIRS}")
message(STATUS "OpenCL CXX includes: ${OPENCL_HAS_CPP_BINDINGS}")
message(STATUS "OpenCL libraries: ${OPENCL_LIBRARIES}")

#target_link_libraries(cpl OpenCL)

And this is the error I'm getting:

C:\Users\drathier\.CLion2016.1\system\cygwin_cmake\bin\cmake.exe --build C:\Users\drathier\.CLion2016.1\system\cmake\generated\cpl-bfc654e8\bfc654e8\Debug --target all -- -j 8
-- Boost version: 1.60.0
CMake Error at /cygdrive/c/Users/drathier/.CLion2016.1/system/cygwin_cmake/share/cmake-3.5.1/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
  Could NOT find OpenCL (missing: OpenCL_LIBRARY)
Call Stack (most recent call first):
  /cygdrive/c/Users/drathier/.CLion2016.1/system/cygwin_cmake/share/cmake-3.5.1/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
  /cygdrive/c/Users/drathier/.CLion2016.1/system/cygwin_cmake/share/cmake-3.5.1/Modules/FindOpenCL.cmake:128 (find_package_handle_standard_args)
  CMakeLists.txt:22 (find_package)

CMakeOutput.log: http://pastebin.com/EgGyRk9H

like image 608
Filip Haglund Avatar asked May 08 '16 13:05

Filip Haglund


1 Answers

In cases where the FindOpenCL CMake Module used by find_package fails to find you OpenCL installation, you can override it with the following arguments to CMake

-DOpenCL_FOUND=True -DOpenCL_LIBRARY=<PUT_LIBRARY_PATH_HERE>

The include path can also be manually set via, OpenCL_INCLUDE_DIR, see the documentation.


The FindOpenCL module (see source, might look different in your version) checks a number of things to identify some OpenCL SDKs, for instance typical environment variables exported by OpenCL installations:

    ENV "PROGRAMFILES(X86)"
    ENV AMDAPPSDKROOT
    ENV INTELOCLSDKROOT
    ENV CUDA_PATH
    ENV NVSDKCOMPUTE_ROOT
    ENV ATISTREAMSDKROOT
    ENV OCL_ROOT

You could check if at least on of these is exported with the correct path, and if not set it yourself, to avoid the manual override described above. Your CMakeLists.txt indicates that CUDA_PATH should be set, so maybe check that value first. A Further path to debugging could be adding some output to the FindOpenCL module.

Hope that helps & good luck.

like image 154
noma Avatar answered Sep 28 '22 01:09

noma