1、在cmakelist.txt中加入:
include(src/main/cpp/dlib/cmake)
然后再链接dlib库就可以了:
target_link_libraries( # Specifies the target library.
native-lib
dlib
# Links the target library to the log library
# included in the NDK.
${log-lib} )
2、可能出现的错误
Android NDK 编译器默认不支持 C++ 异常控制导致。
Error:(124, 17) error: cannot use 'throw' with exceptions disabled
Error:(119, 21) error: cannot use typeid with -fno-rtti
在build.gradle中加入cpp编译选项:
cppFlags "-fexceptions"
cppFlags "-frtti"
最后build文件如下:
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "image.imageapp"
minSdkVersion 19
targetSdkVersion 24
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags "-std=c++11"
cppFlags "-fexceptions"
cppFlags "-frtti"
}
}
}
4、找不到opencv.cmake
SET(OpenCV_INCLUDE_DIRS "/usr/include")
SET(OpenCV_LIB_DIR "/usr/lib")
INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS})
5、找不到
gnu/stubs-64.h那么:
apt-get install libc6-dev-amd64