From 6fc569795070db21a19342624e8913e58c1f3262 Mon Sep 17 00:00:00 2001 From: Ricardo Ribalda Delgado Date: Wed, 23 Aug 2017 15:45:38 +0200 Subject: [PATCH] ocl: Fix OpenCL library detection in Linux OpenCL runtime does not require OpenCL development file (libOpenCL.so), just the "run" library (so.1). This patch searches for the run library (so.1) if the dev library (.so) is not found. Web search shows that this error has been present since at least 2015 http://answers.opencv.org/question/80532/haveopencl-return-false/ Signed-off-by: Ricardo Ribalda Delgado --- .../core/src/opencl/runtime/opencl_core.cpp | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/modules/core/src/opencl/runtime/opencl_core.cpp b/modules/core/src/opencl/runtime/opencl_core.cpp index 34ae5d8311..9ad51b2109 100644 --- a/modules/core/src/opencl/runtime/opencl_core.cpp +++ b/modules/core/src/opencl/runtime/opencl_core.cpp @@ -134,6 +134,24 @@ static void* WinGetProcAddress(const char* name) #include #include +static void *GetHandle(const char *file) +{ + void *handle; + + handle = dlopen(file, RTLD_LAZY | RTLD_GLOBAL); + if (!handle) + return NULL; + + if (dlsym(handle, OPENCL_FUNC_TO_CHECK_1_1) == NULL) + { + fprintf(stderr, ERROR_MSG_INVALID_VERSION); + dlclose(handle); + return NULL; + } + + return handle; +} + static void* GetProcAddress(const char* name) { static bool initialized = false; @@ -143,20 +161,18 @@ static void* GetProcAddress(const char* name) cv::AutoLock lock(cv::getInitializationMutex()); if (!initialized) { - const char* path = "libOpenCL.so"; const char* envPath = getenv("OPENCV_OPENCL_RUNTIME"); if (envPath) - path = envPath; - handle = dlopen(path, RTLD_LAZY | RTLD_GLOBAL); - if (handle == NULL) { - if (envPath) + handle = GetHandle(envPath); + if (!handle) fprintf(stderr, ERROR_MSG_CANT_LOAD); } - else if (dlsym(handle, OPENCL_FUNC_TO_CHECK_1_1) == NULL) + else { - fprintf(stderr, ERROR_MSG_INVALID_VERSION); - handle = NULL; + handle = GetHandle("libOpenCL.so"); + if (!handle) + handle = GetHandle("libOpenCL.so.1"); } initialized = true; }