2

I am trying to build an openCL program in Android Studio and keep running into the following issue:

Android Studio fatal error: CL/cl.h No such file or directory

I have been searching and everything is a solution for "visual studio".

I thought it may be helpful if we had a solution listed specifically for Android Studio and this error.

Any ideas how to fix this? I see references here appears to be running gcc from command line. I want this to work just from Android Studio.

Community
  • 1
  • 1
Seanoseanohay
  • 341
  • 4
  • 19

1 Answers1

1

OpenCL is not part of Android, so you cannot find cl.h. Download necessary CL header files from here: https://www.khronos.org/registry/cl/

Download the cl.h with the correct version (same as the CL version you are using, for example, CL 1.1).

Include the header files in your OpenCL program, then you are good to go.


Edited 4/18/2015:

To include the OpenCL header files, you can do the following:

#ifdef __APPLE__
#include <OpenCL/opencl.h>
#else
#include <CL/opencl.h>
#endif

But if you program is a purely CL code (without CL-GL interoperability), simply including CL/cl.h should also work:

#include <CL/cl.h>

After doing this, you should add the folder that contains CL folder into the include path in your makefile. (The following assumes that PATH_TO_CL_FOLDER is your CL folder)

For those who use Android.mk

If you work with Application.mk and Android.mk, and build your native library using traditional ndk-build way, you should add the path to CL directory into the LOCAL_C_INCLUDES variable in Android.mk).

LOCAL_C_INCLUDES += PATH_TO_CL_FOLDER

For those who work with Gradle in Android Studio (This is what you need)

Edit build.gradle, add your include path in the cFlags field as shown below:

android {
  defaultConfig {
    ndk {
                moduleName "yourlib"
                stl "stlport_static"
                ldLibs "log", "z"
                cFlags "-IPATH_TO_CL_FOLDER"
        }
    ...
  }
  ...
}
Robert Wang
  • 1,161
  • 9
  • 15