arrayfire/androidcl

jni/libs/libOpenCL.so: error adding symbols: File in wrong format

ashokbugude opened this issue · 10 comments

Hi,
I have generated libOpenCL.so by running the following command in windows 10

C:\Users\H242018\AppData\Local\Android\sdk\platform-tools>adb pull /system/vendor/lib/libOpenCL.so ./
/system/vendor/lib/libOpenCL.so: 1 file pulled. 0.6 MB/s (75924 bytes in 0.120s)

I copied the generated file and pasted in jni/libs folder of androidcl project and ran the following command

C:\Users\H242018\Downloads\androidcl-master\androidcl-master>ndk-build
Android NDK: WARNING:jni/Android.mk:JNIProcessor: non-system libraries in linker flags: jni/libs/libOpenCL.so
Android NDK: This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK: or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
Android NDK: current module
Android NDK: WARNING:jni/Android.mk:JNIProcessor: non-system libraries in linker flags: jni/libs/libOpenCL.so
Android NDK: This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK: or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
Android NDK: current module
Android NDK: WARNING:jni/Android.mk:JNIProcessor: non-system libraries in linker flags: jni/libs/libOpenCL.so
Android NDK: This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK: or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
Android NDK: current module
Android NDK: WARNING:jni/Android.mk:JNIProcessor: non-system libraries in linker flags: jni/libs/libOpenCL.so
Android NDK: This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK: or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
Android NDK: current module
Android NDK: WARNING:jni/Android.mk:JNIProcessor: non-system libraries in linker flags: jni/libs/libOpenCL.so
Android NDK: This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK: or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
Android NDK: current module
Android NDK: WARNING:jni/Android.mk:JNIProcessor: non-system libraries in linker flags: jni/libs/libOpenCL.so
Android NDK: This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK: or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
Android NDK: current module
Android NDK: WARNING:jni/Android.mk:JNIProcessor: non-system libraries in linker flags: jni/libs/libOpenCL.so
Android NDK: This is likely to result in incorrect builds. Try using LOCAL_STATIC_LIBRARIES
Android NDK: or LOCAL_SHARED_LIBRARIES instead to list the library dependencies of the
Android NDK: current module
[arm64-v8a] SharedLibrary : libJNIProcessor.so
jni/libs/libOpenCL.so: error adding symbols: File in wrong format
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [obj/local/arm64-v8a/libJNIProcessor.so] Error 1

C:\Users\H242018\Downloads\androidcl-master\androidcl-master>

I am getting jni/libs/libOpenCL.so: error adding symbols: File in wrong format as seen above. Kindly help

@ashokbugude Honestly, the code in this repo hasn't been built against newer versions of Android SDK or against the newer OpenCL libs provided by any vendor. So, I can't say for sure what's causing this incorrect format error. Are you sure the file you copied from the device is not corrupted ? Does verbose mode build command show any additional information as to why the linking stage failed ? For which mobile device are you trying this for ? - If I can get my hands on it, may be I can give it a try.

I am able to build and run the app in my mobile, it was because of old version of code
But when I run, the app opens and closes immediately with below error

A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0xe9 in tid 12585 after executing code like

/* Create Kernel Program from the source */
program = clCreateProgramWithSource(context, 1, (const char **)&CLCL_HELLO,
(const size_t *)strlen(CLCL_HELLO), &ret);

Please help me in resolving it

You haven't mentioned which mobile device is it you are trying to get the program running on ?

Sorry, I am using Vivo V5 device

Unfortunately, my phone is Nexus 5x and it doesn't provide libOpenCL.so. So, I can't check this out on my end. Can you try running a simple OpenCL program that prints the device information to standard output and see if such program executes fine? that should let you know if the issue is with the opencl lib file or otherwise.

Hi I am able to print device info

  1. Device: QUALCOMM Adreno(TM)
    1.1 Hardware version: OpenCL 2.0 Adreno(TM) 505
    1.2 Software version: OpenCL 2.0 QUALCOMM build: commit #86537f4 changeid #I10b006b743 Date: 03/24/17 Fri Local Branch: Remote Branch: refs/tags/AU_LINUX_ANDROID_LA.UM.5.3.C4.06.00.01.272.042 Compiler E031.29.02.03
    1.3 OpenCL C version: OpenCL C 2.0 Adreno(TM) 505
    1.4 Parallel compute units: 1

Okay, it looks like you are able to find the devices from OpenCL program.

I faintly remember that we need to copy the kernel source files to a path on mobile device as part of the apk package if the kernel source strings are not part of the source code itself. How is the string CLCL_HELLO generated ?

For example in the example illustrated in this repository, we had opencl kernels placed under the assets folder of the android project and when the app is built, they are copied over to the device as part of the apk and we referred to the files in here.

I am trying to run simple hello world program present in https://www.fixstars.com/en/opencl/book/OpenCLProgrammingBook/first-opencl-program/

I have set the string CLCL_HELLO/source_string as Kernel Program . For now I have hard coded the string as

const char source_str =
"__kernel void hello(__global char
string)\n"
"{\n"
" string[0] = 'H';\n"
" string[1] = 'e';\n"
" string[2] = 'l';\n"
" string[3] = 'l';\n"
" string[4] = 'o';\n"
" string[5] = '\0';\n"
"}\n"
"";

Attaching the code of opencl program
openCLCode.txt

I resolved the issue by replacing '(const size_t *)strlen(CLCL_HELLO)' with NULL in
program = clCreateProgramWithSource(context, 1, (const char **)&CLCL_HELLO,
(const size_t *)strlen(CLCL_HELLO), &ret);

@ashokbugude,

I see the same error as you:
jni/../external/libOpenCL_system.so: error adding symbols: File in wrong format
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

What did you mean when you said you changed the version of the code?