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

喜夏-厌秋 提交于 2020-01-01 19:16:13

问题


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.


回答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"
        }
    ...
  }
  ...
}


来源:https://stackoverflow.com/questions/29082524/android-studio-fatal-error-cl-cl-h-no-such-file-or-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!