android - 将特征添加到android

标签 android cmake android-ndk eigen

您好,我在尝试包含 Eigen 时遇到一些问题进入我的 android ndk 项目。

这是我在尝试运行应用程序时收到的错误消息:

Build command failed.
Error while executing process C:\Users\Andrew\AppData\Local\Android\Sdk\cmake\3.10.2.4988404\bin\cmake.exe with arguments {--build D:\newnativetest\app\.externalNativeBuild\cmake\debug\arm64-v8a --target native-lib}
[1/2] Building CXX object CMakeFiles/native-lib.dir/native-lib.cpp.o
FAILED: CMakeFiles/native-lib.dir/native-lib.cpp.o 
C:\Users\Andrew\AppData\Local\Android\sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe -target aarch64-none-linux-android -gcc-toolchain C:/Users/Andrew/AppData/Local/Android/sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/windows-x86_64 --sysroot=C:/Users/Andrew/AppData/Local/Android/sdk/ndk-bundle/platforms/android-21/arch-arm64  -Dnative_lib_EXPORTS -ID:/newnativetest/app/src/main/cpp/Eigen -isystem C:/Users/Andrew/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem C:/Users/Andrew/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/arm64-v8a/include -isystem C:/Users/Andrew/AppData/Local/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -std=c++11 -O0 -fno-limit-debug-info  -fPIC -MD -MT CMakeFiles/native-lib.dir/native-lib.cpp.o -MF CMakeFiles\native-lib.dir\native-lib.cpp.o.d -o CMakeFiles/native-lib.dir/native-lib.cpp.o -c D:/newnativetest/app/src/main/cpp/native-lib.cpp
In file included from D:/newnativetest/app/src/main/cpp/native-lib.cpp:3:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/Core:458:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/src/Core/Matrix.h:14:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/src/Core/../../Eigen:1:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/Dense:2:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/LU:28:
D:/newnativetest/app/src/main/cpp/Eigen/src/LU/FullPivLU.h:255:24: error: no member named 'rcond_estimate_helper' in namespace 'Eigen::internal'
      return internal::rcond_estimate_helper(m_l1_norm, *this);
             ~~~~~~~~~~^
In file included from D:/newnativetest/app/src/main/cpp/native-lib.cpp:3:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/Core:458:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/src/Core/Matrix.h:14:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/src/Core/../../Eigen:1:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/Dense:2:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/LU:29:
D:/newnativetest/app/src/main/cpp/Eigen/src/LU/PartialPivLU.h:187:24: error: no member named 'rcond_estimate_helper' in namespace 'Eigen::internal'
      return internal::rcond_estimate_helper(m_l1_norm, *this);
             ~~~~~~~~~~^
In file included from D:/newnativetest/app/src/main/cpp/native-lib.cpp:3:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/Core:458:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/src/Core/Matrix.h:14:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/src/Core/../../Eigen:1:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/Dense:3:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/Cholesky:32:
D:/newnativetest/app/src/main/cpp/Eigen/src/Cholesky/LLT.h:165:24: error: no member named 'rcond_estimate_helper' in namespace 'Eigen::internal'
      return internal::rcond_estimate_helper(m_l1_norm, *this);
             ~~~~~~~~~~^
D:/newnativetest/app/src/main/cpp/Eigen/src/Cholesky/LLT.h:535:36: error: out-of-line definition of 'llt' from class 'SelfAdjointView<MatrixType, Mode>' without definition
SelfAdjointView<MatrixType, UpLo>::llt() const
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
D:/newnativetest/app/src/main/cpp/Eigen/src/Cholesky/LLT.h:537:14: error: use of undeclared identifier 'PlainObject'
  return LLT<PlainObject,UpLo>(m_matrix);
             ^
In file included from D:/newnativetest/app/src/main/cpp/native-lib.cpp:3:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/Core:458:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/src/Core/Matrix.h:14:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/src/Core/../../Eigen:1:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/Dense:3:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/Cholesky:33:
D:/newnativetest/app/src/main/cpp/Eigen/src/Cholesky/LDLT.h:220:24: error: no member named 'rcond_estimate_helper' in namespace 'Eigen::internal'
      return internal::rcond_estimate_helper(m_l1_norm, *this);
             ~~~~~~~~~~^
D:/newnativetest/app/src/main/cpp/Eigen/src/Cholesky/LDLT.h:654:36: error: out-of-line definition of 'ldlt' from class 'SelfAdjointView<MatrixType, Mode>' without definition
SelfAdjointView<MatrixType, UpLo>::ldlt() const
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
D:/newnativetest/app/src/main/cpp/Eigen/src/Cholesky/LDLT.h:656:15: error: use of undeclared identifier 'PlainObject'
  return LDLT<PlainObject,UpLo>(m_matrix);
              ^
In file included from D:/newnativetest/app/src/main/cpp/native-lib.cpp:3:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/Core:365:
D:/newnativetest/app/src/main/cpp/Eigen/src/Core/util/ForwardDeclarations.h:121:63: error: implicit instantiation of undefined template 'Eigen::Array<long, 1, -1, 1, 1, -1>'
         typename StrideType = typename internal::conditional<PlainObjectType::IsVectorAtCompileTime,InnerStride<1>,OuterStride<> >::type > class Ref;
                                                              ^
D:/newnativetest/app/src/main/cpp/Eigen/src/SVD/BDCSVD.h:101:11: note: in instantiation of default argument for 'Ref<Eigen::Array<long, 1, -1, 1, 1, -1>, 0>' required here
  typedef Ref<ArrayXi> IndicesRef;
          ^~~~~~~~~~~~
D:/newnativetest/app/src/main/cpp/Eigen/src/Core/util/ForwardDeclarations.h:242:60: note: template is declared here
         int _MaxRows = _Rows, int _MaxCols = _Cols> class Array;
                                                           ^
In file included from D:/newnativetest/app/src/main/cpp/native-lib.cpp:3:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/Core:458:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/src/Core/Matrix.h:14:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/src/Core/../../Eigen:1:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/Dense:5:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/SVD:38:
D:/newnativetest/app/src/main/cpp/Eigen/src/SVD/BDCSVD.h:193:11: error: implicit instantiation of undefined template 'Eigen::Array<long, 1, -1, 1, 1, -1>'
  ArrayXi m_workspaceI;
          ^
D:/newnativetest/app/src/main/cpp/Eigen/src/Core/util/ForwardDeclarations.h:242:60: note: template is declared here
         int _MaxRows = _Rows, int _MaxCols = _Cols> class Array;
                                                           ^
In file included from D:/newnativetest/app/src/main/cpp/native-lib.cpp:3:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/Core:458:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/src/Core/Matrix.h:14:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/src/Core/../../Eigen:1:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/Dense:5:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/SVD:38:
D:/newnativetest/app/src/main/cpp/Eigen/src/SVD/BDCSVD.h:599:16: error: implicit instantiation of undefined template 'Eigen::Map<Eigen::Array<long, 1, -1, 1, 1, -1>, 0, Eigen::Stride<0, 0> >'
  Map<ArrayXi> perm(m_workspaceI.data(),m);
               ^
D:/newnativetest/app/src/main/cpp/Eigen/src/Core/util/ForwardDeclarations.h:118:99: note: template is declared here
template<typename MatrixType, int MapOptions=Unaligned, typename StrideType = Stride<0,0> > class Map;
                                                                                                  ^
In file included from D:/newnativetest/app/src/main/cpp/native-lib.cpp:3:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/Core:458:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/src/Core/Matrix.h:14:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/src/Core/../../Eigen:1:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/Dense:5:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/SVD:38:
D:/newnativetest/app/src/main/cpp/Eigen/src/SVD/BDCSVD.h:694:17: error: member reference base type 'const IndicesRef' (aka 'const int') is not a structure or union
  Index m = perm.size();
            ~~~~^~~~~
D:/newnativetest/app/src/main/cpp/Eigen/src/SVD/BDCSVD.h:698:19: error: called object type 'IndicesRef' (aka 'int') is not a function or function pointer
    Index j = perm(i);
              ~~~~^
D:/newnativetest/app/src/main/cpp/Eigen/src/SVD/BDCSVD.h:901:17: error: member reference base type 'const IndicesRef' (aka 'const int') is not a structure or union
  Index m = perm.size();
            ~~~~^~~~~
D:/newnativetest/app/src/main/cpp/Eigen/src/SVD/BDCSVD.h:907:20: error: called object type 'IndicesRef' (aka 'int') is not a function or function pointer
  Index last = perm(m-1);
               ~~~~^
D:/newnativetest/app/src/main/cpp/Eigen/src/SVD/BDCSVD.h:921:23: error: called object type 'IndicesRef' (aka 'int') is not a function or function pointer
        Index i = perm(l);
                  ~~~~^
D:/newnativetest/app/src/main/cpp/Eigen/src/SVD/BDCSVD.h:924:35: error: called object type 'IndicesRef' (aka 'int') is not a function or function pointer
          Index j = i<k ? i : perm(l-1);
                              ~~~~^
D:/newnativetest/app/src/main/cpp/Eigen/src/SVD/BDCSVD.h:949:17: error: member reference base type 'const IndicesRef' (aka 'const int') is not a structure or union
  Index m = perm.size();
            ~~~~^~~~~
D:/newnativetest/app/src/main/cpp/Eigen/src/SVD/BDCSVD.h:963:23: error: called object type 'IndicesRef' (aka 'int') is not a function or function pointer
        Index i = perm(l);
                  ~~~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
ninja: build stopped: subcommand failed.



这是我第一次尝试将外部库包含到我的 android 项目中,因此这个问题可能很明显但我尝试遵循此问题的答案 question .

我将在下面附上我认为相关的文件,如果您还需要其他任何内容,请告诉我。

CMakeLists.txt

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

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)

# 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( # Sets the name of the library.
             native-lib

             # Sets the library as a shared library.
             SHARED

             # Provides a relative path to your source file(s).
             native-lib.cpp )

include_directories(src/main/cpp/Eigen)

# 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( # Specifies the target library.
                       native-lib

                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib} )

构建.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion "29.0.0"
    defaultConfig {
        applicationId "com.gpcsl.myapplication"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        externalNativeBuild {
            cmake {
                cppFlags "-std=c++11"
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            path "src/main/cpp/CMakeLists.txt"
            version "3.10.2"
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

Native-lib.cpp

#include <jni.h>
#include <string>
#include "Eigen/Core"

extern "C" JNIEXPORT jstring JNICALL
Java_com_gpcsl_myapplication_MainActivity_stringFromJNI(JNIEnv *env,jobject /* this */)
{
    Eigen::Matrix2d b;


    std::string hello = "Hello from C++";
    return env->NewStringUTF(hello.c_str());
}

我还注意到,如果我实际打开任何 Eigen src 文件,则会出现很多错误,例如:Example

最佳答案

请勿在 Eigen/src/ 目录下包含任何内容。这本质上是内部实现。您想要包含 #include "Eigen/Core"#include "Eigen/Dense,而不是 #include "Eigen/src/Core/Matrix.h"

基于 chtz 的 comment ,实际问题是内部实现被OP修改了,使得内部实现包含了暴露的API。从编译器错误中可以明显看出这一点:

In file included from D:/newnativetest/app/src/main/cpp/Eigen/src/Core/Matrix.h:14:
In file included from D:/newnativetest/app/src/main/cpp/Eigen/src/Core/../../Eigen:1:

关于android - 将特征添加到android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59307786/

相关文章:

android-studio - 为什么我会收到此 Android Studio 错误 : "recompile with -fPIC"?

c++ - 防止在 C++ 中以错误的顺序将值传递给函数/构造函数

android - 如何制作自己的广告 android SDK?

java - 如何将ListView添加到fragment_main.xml

c++ - macOS 中的 CMake,预编译头文件 (.pch) 支持

android - 将 Android NDK 库限制为特定应用程序

android - 链接Android NDK下的共享库

android - 如何在 Android NDK 应用程序中使用 GLM

android - 拒绝外设触摸输入

android - 如何在 Android 的 ViewPager 中增加 child 的宽度?