0

Question Update:

Linker error

I installed Intel OpenCL SDK with Android Support on dev pc.

Difficulty building Android Studio Solution with C++ support using CMakelists.txt

OpenCL & OpenCV in Android Studio using CMakeLists.txt

CMakeLists.txt:

# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html


#Added 2 path definitions to support 20160825 additions
set(pathToProject C:/Users/eogha/Desktop/HelloOpenCV)
set(pathToOpenCv C:/OpenCV-3.1.0-android-sdk)

set(pathToOpenCL "C:/Program Files (x86)/Intel/OpenCL SDK/5.3")


# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)

set(CMAKE_VERBOSE_MAKEFILE on)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")


#Addition suggested by Bruno Alexandre Krinski 20160825
include_directories(${pathToOpenCv}/sdk/native/jni/include )

include_directories(${pathToOpenCL}/include)


# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

add_library( native-lib SHARED src/main/cpp/native-lib.cpp )


#Addition suggested by Bruno Alexandre Krinski 20160825
add_library( lib_opencv SHARED IMPORTED )


#Addition suggested by Bruno Alexandre Krinski 20160825
set_target_properties(  lib_opencv PROPERTIES IMPORTED_LOCATION 
${pathToProject}/app/src/main/jniLibs/${ANDROID_ABI}/libopencv_java3.so )

add_library( lib_opencl SHARED IMPORTED )
set_target_properties(  lib_opencl PROPERTIES IMPORTED_LOCATION "C:/Program 
Files (x86)/Intel/OpenCL SDK/5.3/lib/android64/libOpenCL.so" )


# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
          log-lib

          # Specifies the name of the NDK library that
          # you want CMake to locate.
          log )

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( native-lib $\{log-lib} lib_opencv lib_opencl )

Android Studio Error: linker command failed with exit code 1 (use -v to see invocation)

Finally !! The OpenCL Shared Object library seems to be imported into the android project structure. But now I have this linker error. How do I resolve this in Windows 10 ??

Saif
  • 723
  • 6
  • 21
Eoghan Hynes
  • 41
  • 11
  • Error "Undefined reference" is unrelated with header files. Update your question post with content of `CMakeLists.txt` and **exact** error messages (at least, some of "undefined reference"). – Tsyvarev Nov 30 '17 at 13:18
  • The native-lib.cpp is calling clGetPlatformIDs which seems to be declared in cl.h. How do I tell CMakeLists.txt that native-lib.cpp needs cl.h ?? – Eoghan Hynes Nov 30 '17 at 14:59
  • `... calling clGetPlatformIDs which seems to be declared in cl.h` - `clGetPlatformIDs` is *declared* (as function's prototype) in `cl.h`, but **defined** (as function with budy) in `OpenCL` library. You need to **link** (`target_link_libraries()`) with that library, like you link with `OpenCV`. – Tsyvarev Nov 30 '17 at 17:04
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Tsyvarev Nov 30 '17 at 17:05
  • I dont know how to write CMake. I need help to link to OpenCL. I have updated the question with more detail. – Eoghan Hynes Dec 01 '17 at 14:52
  • Correct: `target_link_libraries( native-lib ${log-lib} lib_opencv lib_opencl)`. If you don't know how to use CMake command, why do not consult [documentation](https://cmake.org/cmake/help/v3.9/command/target_link_libraries.html)? – Tsyvarev Dec 01 '17 at 19:24
  • Thanks for your help so far. I have updated the problem. – Eoghan Hynes Dec 04 '17 at 14:03
  • This line: `set(pathToOpenCL C:/Program Files (x86)/Intel/OpenCL SDK/5.3)` - You need to use quotes around the path string containing spaces. – Tsyvarev Dec 04 '17 at 17:28
  • Thank you for your help. I have updated the post. OpenCL library is now in the project, but I have a linker error that I can't resolve. – Eoghan Hynes Dec 06 '17 at 10:44
  • The question post currently doesn't contain linker error. Did you forgot to add it? – Tsyvarev Dec 06 '17 at 10:59
  • All I see in Android Studio is: linker command failed with exit code 1 (use -v to see invocation) I don't know how to use -v ?? – Eoghan Hynes Dec 06 '17 at 13:25

0 Answers0