我尝试使用Gradle实验0.4.0在我的Android Studio 1.5中运行OpenCV 3.0.0原生。
我已经可以使用OpenCV的Java组件和常规的NDK功能。但是当我尝试在我的本机代码中使用命名空间cv时,我得到以下异常(它被缩短。完整的异常太长了):
app\src\main\jniLibs\armeabi\libopencv_core.a(matrix.cpp.o):matrix.cpp:function std::vector<unsigned char, std::allocator<unsigned char> >::resize(unsigned int, unsigned char): error: undefined reference to 'std::__throw_length_error(char const*)'
app\src\main\jniLibs\armeabi\libopencv_core.a(matrix.cpp.o):matrix.cpp:function std::vector<int, std::allocator<int> >::resize(unsigned int, int): error: undefined reference to 'std::__throw_length_error(char const*)'
app\src\main\jniLibs\armeabi\libopencv_core.a(matrix.cpp.o):matrix.cpp:function std::vector<unsigned int, std::allocator<unsigned int> >::operator=(std::vector<unsigned int, std::allocator<unsigned int> > const&): error: undefined reference to 'std::__throw_bad_alloc()'
app\src\main\jniLibs\armeabi\libopencv_core.a(matrix.cpp.o):matrix.cpp:function cv::SparseMat::resizeHashTab(unsigned int): error: undefined reference to 'std::__throw_bad_alloc()'
app\src\main\jniLibs\armeabi\libopencv_core.a(matrix.cpp.o):matrix.cpp:function std::vector<unsigned char, std::allocator<unsigned char> >::_M_fill_insert(__gnu_cxx::__normal_iterator<unsigned char*, std::vector<unsigned char, std::allocator<unsigned char> > >, unsigned int, unsigned char const&): error: undefined reference to 'std::__throw_length_error(char const*)'
app\src\main\jniLibs\armeabi\libopencv_core.a(matrix.cpp.o):matrix.cpp:function std::vector<cv::Vec<unsigned char, 2>, std::allocator<cv::Vec<unsigned char, 2> > >::_M_fill_insert(__gnu_cxx::__normal_iterator<cv::Vec<unsigned char, 2>*, std::vector<cv::Vec<unsigned char, 2>, std::allocator<cv::Vec<unsigned char, 2> > > >, unsigned int, cv::Vec<unsigned char, 2> const&): error: undefined reference to 'std::__throw_length_error(char const*)'
app\src\main\jniLibs\armeabi\libopencv_core.a(system.cpp.o):system.cpp:function cv::error(cv::Exception const&): error: undefined reference to '__android_log_print'
app\src\main\jniLibs\armeabi\libopencv_core.a(convert.cpp.o):convert.cpp:function std::vector<cv::Mat, std::allocator<cv::Mat> >::vector(unsigned int, cv::Mat const&, std::allocator<cv::Mat> const&): error: undefined reference to 'std::__throw_bad_alloc()'
app\src\main\jniLibs\armeabi\libopencv_core.a(kmeans.cpp.o):kmeans.cpp:function cv::kmeans(cv::_InputArray const&, int, cv::_InputOutputArray const&, cv::TermCriteria, int, int, cv::_OutputArray const&): error: undefined reference to 'std::__throw_bad_alloc()'
app\src\main\jniLibs\armeabi\libopencv_core.a(ocl.cpp.o):ocl.cpp:function std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) [clone .part.37]: error: undefined reference to 'std::basic_ios<char, std::char_traits<char> >::clear(std::_Ios_Iostate)'
app\src\main\jniLibs\armeabi\libopencv_core.a(ocl.cpp.o):ocl.cpp:function std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::~basic_stringbuf(): error: undefined reference to 'std::locale::~locale()'
app\src\main\jniLibs\armeabi\libopencv_core.a(ocl.cpp.o):ocl.cpp:function std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::~basic_stringbuf(): error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator<char> const&)'
app\src\main\jniLibs\armeabi\libopencv_core.a(ocl.cpp.o):ocl.cpp:function std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::~basic_stringbuf(): error: undefined reference to 'vtable for std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >'
ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/ld.exe: the vtable symbol may be undefined because the class is missing its key function
ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/ld.exe: the vtable symbol may be undefined because the class is missing its key function
ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/ld.exe: the vtable symbol may be undefined because the class is missing its key function
ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/ld.exe: the vtable symbol may be undefined because the class is missing its key function
ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../arm-linux-androideabi/bin/ld.exe: the vtable symbol may be undefined because the class is missing its key function
app\src\main\jniLibs\armeabi\libopencv_core.a(ocl.cpp.o):ocl.cpp:function std::string cv::ocl::kerToStr<float>(cv::Mat const&): error: undefined reference to 'std::ostream& std::ostream::_M_insert<double>(double)'
app\src\main\jniLibs\armeabi\libopencv_core.a(ocl.cpp.o):ocl.cpp:function std::string cv::ocl::kerToStr<float>(cv::Mat const&): error: undefined reference to 'std::ostream& std::ostream::_M_insert<double>(double)'
app\src\main\jniLibs\armeabi\libopencv_core.a(ocl.cpp.o):ocl.cpp:function std::string cv::ocl::kerToStr<float>(cv::Mat const&): error: undefined reference to 'std::ostream& std::ostream::_M_insert<double>(double)'
app\src\main\jniLibs\armeabi\libopencv_core.a(ocl.cpp.o):ocl.cpp:function std::string cv::ocl::kerToStr<float>(cv::Mat const&): error: undefined reference to 'std::ostream& std::ostream::_M_insert<double>(double)'
...
app\src\main\jniLibs\armeabi\libopencv_core.a(ocl.cpp.o):ocl.cpp:function cv::ocl::Context::Impl::setDefault(): error: undefined reference to 'std::string::assign(std::string const&)'
app\src\main\jniLibs\armeabi\libopencv_core.a(ocl.cpp.o):ocl.cpp:function cv::ocl::Context::Impl::setDefault(): error: undefined reference to 'std::string::assign(std::string const&)'
app\src\main\jniLibs\armeabi\libopencv_core.a(ocl.cpp.o):ocl.cpp:function cv::ocl::Context::Impl::setDefault(): error: undefined reference to 'std::ctype<char>::_M_widen_init() const'
app\src\main\jniLibs\armeabi\libopencv_core.a(ocl.cpp.o):ocl.cpp:function cv::ocl::Context::Impl::setDefault(): error: undefined reference to 'std::__throw_bad_cast()'
app\src\main\jniLibs\armeabi\libopencv_core.a(ocl.cpp.o):ocl.cpp:function cv::ocl::Context::Impl::setDefault(): error: undefined reference to 'std::cerr'
app\src\main\jniLibs\armeabi\libopencv_core.a(ocl.cpp.o):ocl.cpp:function cv::ocl::OpenCLBufferPoolImpl::_allocateBufferEntry(cv::ocl::CLBufferEntry&, unsigned int): error: undefined reference to 'std::__detail::_List_node_base::_M_hook(std::__detail::_List_node_base*)'
app\src\main\jniLibs\armeabi\libopencv_core.a(ocl.cpp.o):ocl.cpp:function _GLOBAL__sub_I_ocl.cpp: error: undefined reference to 'std::ios_base::Init::Init()'
app\src\main\jniLibs\armeabi\libopencv_core.a(ocl.cpp.o):ocl.cpp:function _GLOBAL__sub_I_ocl.cpp: error: undefined reference to 'std::ios_base::Init::~Init()'
app\src\main\jniLibs\armeabi\libopencv_core.a(persistence.cpp.o):persistence.cpp:function icvPuts(CvFileStorage*, char const*): error: undefined reference to 'gzputs'
app\src\main\jniLibs\armeabi\libopencv_core.a(persistence.cpp.o):persistence.cpp:function icvGets(CvFileStorage*, char*, int): error: undefined reference to 'gzgets'
app\src\main\jniLibs\armeabi\libopencv_core.a(persistence.cpp.o):persistence.cpp:function icvXMLSkipSpaces(CvFileStorage*, char*, int): error: undefined reference to 'gzeof'
app\src\main\jniLibs\armeabi\libopencv_core.a(persistence.cpp.o):persistence.cpp:function icvYMLSkipSpaces(CvFileStorage*, char*, int, int) [clone .constprop.113]: error: undefined reference to 'gzeof'
app\src\main\jniLibs\armeabi\libopencv_core.a(persistence.cpp.o):persistence.cpp:function cv::FileStorage::releaseAndGetString(): error: undefined reference to 'gzclose'
app\src\main\jniLibs\armeabi\libopencv_core.a(persistence.cpp.o):persistence.cpp:function cvReleaseFileStorage: error: undefined reference to 'gzclose'
app\src\main\jniLibs\armeabi\libopencv_core.a(persistence.cpp.o):persistence.cpp:function cvOpenFileStorage: error: undefined reference to 'gzrewind'
app\src\main\jniLibs\armeabi\libopencv_core.a(persistence.cpp.o):persistence.cpp:function cvOpenFileStorage: error: undefined reference to 'gzopen'
app\src\main\jniLibs\armeabi\libopencv_core.a(persistence.cpp.o):persistence.cpp:function cvOpenFileStorage: error: undefined reference to 'gzclose'
app\src\main\jniLibs\armeabi\libopencv_core.a(persistence.cpp.o):persistence.cpp:function cvOpenFileStorage: error: undefined reference to 'gzgets'
app\src\main\jniLibs\armeabi\libopencv_core.a(persistence.cpp.o):persistence.cpp:function cvOpenFileStorage: error: undefined reference to 'gzclose'
...
app\src\main\jniLibs\armeabi\libtbb.a(tbb_misc.cpp.o):tbb_misc.cpp:function tbb::internal::throw_exception_v4(tbb::internal::exception_id): error: undefined reference to 'std::runtime_error::~runtime_error()'
app\src\main\jniLibs\armeabi\libtbb.a(tbb_misc.cpp.o):tbb_misc.cpp:function tbb::internal::throw_exception_v4(tbb::internal::exception_id): error: undefined reference to 'typeinfo for std::invalid_argument'
app\src\main\jniLibs\armeabi\libtbb.a(tbb_misc.cpp.o):tbb_misc.cpp:function tbb::internal::throw_exception_v4(tbb::internal::exception_id): error: undefined reference to 'std::invalid_argument::~invalid_argument()'
app\src\main\jniLibs\armeabi\libtbb.a(tbb_misc.cpp.o):tbb_misc.cpp:function tbb::internal::throw_exception_v4(tbb::internal::exception_id): error: undefined reference to 'typeinfo for std::out_of_range'
app\src\main\jniLibs\armeabi\libtbb.a(tbb_misc.cpp.o):tbb_misc.cpp:function tbb::internal::throw_exception_v4(tbb::internal::exception_id): error: undefined reference to 'std::out_of_range::~out_of_range()'
app\src\main\jniLibs\armeabi\libtbb.a(tbb_misc.cpp.o):tbb_misc.cpp:function tbb::internal::throw_exception_v4(tbb::internal::exception_id): error: undefined reference to 'typeinfo for std::range_error'
app\src\main\jniLibs\armeabi\libtbb.a(tbb_misc.cpp.o):tbb_misc.cpp:function tbb::internal::throw_exception_v4(tbb::internal::exception_id): error: undefined reference to 'std::range_error::~range_error()'
app\src\main\jniLibs\armeabi\libtbb.a(tbb_misc.cpp.o):tbb_misc.cpp:function tbb::internal::throw_exception_v4(tbb::internal::exception_id): error: undefined reference to 'typeinfo for std::length_error'
app\src\main\jniLibs\armeabi\libtbb.a(tbb_misc.cpp.o):tbb_misc.cpp:function tbb::internal::throw_exception_v4(tbb::internal::exception_id): error: undefined reference to 'std::length_error::~length_error()'
这是我的gradle文件:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.2"
defaultConfig.with {
applicationId = "com.example.ndktest"
minSdkVersion.apiLevel = 15
targetSdkVersion.apiLevel = 23
}
}
compileOptions.with {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}
/*
* native build settings
*/
android.ndk {
moduleName = "helloJni"
cppFlags.add("-fexceptions")
cppFlags.add("-frtti")
cppFlags.add("-I${file("D:/Android/OpenCV-3.0.0-android-sdk-1/OpenCV-android-sdk/sdk/native/jni/include")}".toString())
cppFlags.add("-I${file("D:/Android/OpenCV-3.0.0-android-sdk-1/OpenCV-android-sdk/sdk/native/jni/include/opencv")}".toString())
stl = "stlport_static"
/*
* Other ndk flags configurable here are
* cppFlags.add("-fno-rtti")
* cppFlags.add("-fno-exceptions")
* ldLibs.addAll(["android", "log"])
* stl = "system"
*/
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles.add(file('proguard-rules.txt'))
}
}
android.productFlavors {
create("armeabi") {
ndk.with {
// You can customize the NDK configurations for each
// productFlavors and buildTypes.
abiFilters.add("armeabi")
File curDir = file('./')
curDir = file(curDir.absolutePath)
String libsDir = curDir.absolutePath + "\\src\\main\\jniLibs\\armeabi\\"
//"-L" +
ldLibs.add(libsDir + "libopencv_calib3d.a")
ldLibs.add(libsDir + "libopencv_core.a")
ldLibs.add(libsDir + "libopencv_features2d.a")
ldLibs.add(libsDir + "libopencv_flann.a")
ldLibs.add(libsDir + "libopencv_hal.a")
ldLibs.add(libsDir + "libopencv_highgui.a")
ldLibs.add(libsDir + "libopencv_imgcodecs.a")
ldLibs.add(libsDir + "libopencv_imgproc.a")
ldLibs.add(libsDir + "libopencv_java3.so")
ldLibs.add(libsDir + "libopencv_ml.a")
ldLibs.add(libsDir + "libopencv_objdetect.a")
ldLibs.add(libsDir + "libopencv_photo.a")
ldLibs.add(libsDir + "libopencv_shape.a")
ldLibs.add(libsDir + "libopencv_stitching.a")
ldLibs.add(libsDir + "libopencv_superres.a")
ldLibs.add(libsDir + "libopencv_ts.a")
ldLibs.add(libsDir + "libopencv_video.a")
ldLibs.add(libsDir + "libopencv_videoio.a")
ldLibs.add(libsDir + "libopencv_videostab.a")
ldLibs.add(libsDir + "libIlmImf.a")
ldLibs.add(libsDir + "liblibjpeg.a")
ldLibs.add(libsDir + "liblibjasper.a")
ldLibs.add(libsDir + "liblibpng.a")
ldLibs.add(libsDir + "liblibwebp.a")
ldLibs.add(libsDir + "liblibtiff.a")
ldLibs.add(libsDir + "libtbb.a")
}
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile project(':openCVLibrary300')
}
缺少什么,我该如何解决?