0

I'm trying to use OpenCV library in my project, but I get this error at runtime :

Build command failed. Error while executing process D:\Sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {-HC:\Users\Mouad AITALI\AndroidStudioProjects\BGREMOVER\app -BC:\Users\Mouad AITALI\AndroidStudioProjects\BGREMOVER\app.cxx\cmake\debug\arm64-v8a -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=android-16 -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\Mouad AITALI\AndroidStudioProjects\BGREMOVER\app\build\intermediates\cmake\debug\obj\arm64-v8a -DCMAKE_BUILD_TYPE=Debug -DANDROID_NDK=D:\Sdk\ndk\19.2.5345600 -DCMAKE_CXX_FLAGS=-std=c++11 -DCMAKE_TOOLCHAIN_FILE=D:\Sdk\ndk\19.2.5345600\build\cmake\android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=D:\Sdk\cmake\3.6.4111459\bin\ninja.exe -GAndroid Gradle - Ninja} -- Configuring incomplete, errors occurred! See also "C:/Users/Mouad AITALI/AndroidStudioProjects/BGREMOVER/app/.cxx/cmake/debug/arm64-v8a/CMakeFiles/CMakeOutput.log".

CMake Error at CMakeLists.txt:13 (set_target_properties):
set_target_properties called with incorrect number of arguments.

CMakeLists.txt

#declare folder path
set(pathToProject C:\\Users\\Mouad;AITALI\\AndroidStudioProjects\\BGREMOVER)

cmake_minimum_required(VERSION 3.4.1)

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

include_directories(${pathToOpenCv}/sdk/native/jni/include)

#library location
add_library(lib_opencv SHARED IMPORTED)
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION ${pathToProject}/app/src/main/jniLibs/${ANDROID_ABI}/libopencv_java3.so)

#define libraries
add_library(native-lib SHARED src/main/cpp/native-lib.cpp)
add_library(grabcut SHARED src/main/cpp/jni-grabcut-lib.cpp src/main/cpp/grabcutter_p.cpp src/main/cpp/grabcutter_p.h)

find_library(log-lib log)

#target libraries
target_link_libraries(native-lib ${log-lib} lib_opencv)
target_link_libraries(grabcut ${log-lib} lib_opencv)
3
  • Your pathToProject variable has a semicolon in the path. Is this intentional? Commented Dec 4, 2019 at 22:28
  • 1
    Wrap the value of IMPORTED_LOCATION into double quotes. Do the same for pathToProject variable's value. Otherwise CMake treats them as a list because of semicolon. Commented Dec 4, 2019 at 22:29
  • @Tsyvarev thank you so much for your comment Commented Dec 4, 2019 at 22:39

1 Answer 1

1

As commented, CMake uses the semicolon ; to define lists. So if the path contains semicolons, you must enclose the definition, and places where you use the variable pathToProject with double quotes:

set(pathToProject "C:\\Users\\Mouad;AITALI\\AndroidStudioProjects\\BGREMOVER")

...

set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION "${pathToProject}/app/src/main/jniLibs/${ANDROID_ABI}/libopencv_java3.so")

The IMPORTED_LOCATION property only takes one value. So when you provide a list for that property, the set_target_properties() command cannot parse the arguments correctly, which yields the error.

Sign up to request clarification or add additional context in comments.

3 Comments

thank you for your answer, I know it's should be another question but I get this now : ninja: error: 'C:/Users/Mouad;AITALI/AndroidStudioProjects/BGREMOVER/app/src/main/jniLibs/arm64-v8a/libopencv_java3.so', needed by '../../../../build/intermediates/cmake/debug/obj/arm64-v8a/libgrabcut.so', missing and no known rule to make it
Does the library libopencv_java3.so actually exist at that location?
On the screenshot between Mouad and AITALI there is a space, not a semicolon as you use in pathToProject variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.