Skip to content

Commit d0509f6

Browse files
committed
Merge pull request opencv#9449 from ribalda:ocv
2 parents 1fc9425 + 6fc5697 commit d0509f6

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

modules/core/src/opencl/runtime/opencl_core.cpp

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,24 @@ static void* WinGetProcAddress(const char* name)
134134
#include <dlfcn.h>
135135
#include <stdio.h>
136136

137+
static void *GetHandle(const char *file)
138+
{
139+
void *handle;
140+
141+
handle = dlopen(file, RTLD_LAZY | RTLD_GLOBAL);
142+
if (!handle)
143+
return NULL;
144+
145+
if (dlsym(handle, OPENCL_FUNC_TO_CHECK_1_1) == NULL)
146+
{
147+
fprintf(stderr, ERROR_MSG_INVALID_VERSION);
148+
dlclose(handle);
149+
return NULL;
150+
}
151+
152+
return handle;
153+
}
154+
137155
static void* GetProcAddress(const char* name)
138156
{
139157
static bool initialized = false;
@@ -143,20 +161,18 @@ static void* GetProcAddress(const char* name)
143161
cv::AutoLock lock(cv::getInitializationMutex());
144162
if (!initialized)
145163
{
146-
const char* path = "libOpenCL.so";
147164
const char* envPath = getenv("OPENCV_OPENCL_RUNTIME");
148165
if (envPath)
149-
path = envPath;
150-
handle = dlopen(path, RTLD_LAZY | RTLD_GLOBAL);
151-
if (handle == NULL)
152166
{
153-
if (envPath)
167+
handle = GetHandle(envPath);
168+
if (!handle)
154169
fprintf(stderr, ERROR_MSG_CANT_LOAD);
155170
}
156-
else if (dlsym(handle, OPENCL_FUNC_TO_CHECK_1_1) == NULL)
171+
else
157172
{
158-
fprintf(stderr, ERROR_MSG_INVALID_VERSION);
159-
handle = NULL;
173+
handle = GetHandle("libOpenCL.so");
174+
if (!handle)
175+
handle = GetHandle("libOpenCL.so.1");
160176
}
161177
initialized = true;
162178
}

0 commit comments

Comments
 (0)