1

目前,我有一个 Android 项目,我在其中使用 JNI(Java 本机接口)来调用 LAPACK C 函数。

我的 JNI 是:

本机-lib.c

#include <jni.h>
#include "lapack/LAPACKE/include/lapack.h"
#include "lapack/LAPACKE/example/lapacke_example_aux.h"
 JNIEXPORT jstring JNICALL
Java_com_example_lapacktest_MainActivity_stringFromJNI(
        JNIEnv *env,
        jobject obj /* this */) {
    char hello[20] = "Hello from C++";
     double A[5][3] = {{1,2,3},{4,5,1},{3,5,2},{4,1,4},{2,5,3}};
     double b[5][2] = {{-10,12},{14,16},{18,-3},{14,12},{16,16}};
     lapack_int info,m,n,lda,ldb,nrhs;

     /* Initialization */
     m = 5;
     n = 3;
     nrhs = 2;
     lda = 5;
     ldb = 5;

     /* Print Entry Matrix */
     print_matrix_colmajor( "Entry Matrix A", m, n, *A, lda );

  return (*env)->NewStringUTF(env,hello);
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.4.1)
project(LapackTest)
add_library( native-lib
        SHARED
        native-lib.c
        #lapack/LAPACKE/example/lapacke_example_aux.c
        )

# Add dependent libraries
add_library(blas STATIC IMPORTED)
set_property(TARGET blas PROPERTY IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/libs/libblas.a)

add_library(lapack STATIC IMPORTED)
set_property(TARGET lapack PROPERTY IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/libs/liblapack.a)


# Location of header files
include_directories(
        ${CMAKE_SOURCE_DIR}/lapack/BLAS
        ${CMAKE_SOURCE_DIR}/lapack/CBLAS
        ${CMAKE_SOURCE_DIR}/lapack/LAPACKE
        ${CMAKE_SOURCE_DIR}/lapack/SRC
        ${CMAKE_SOURCE_DIR}/lapack/TESTING
        ${CMAKE_SOURCE_DIR}/lapack/CBLAS
)

add_subdirectory(lapack)

问题是当我尝试调用 lapack 目录中存在的函数 print_matrix_colmajor() 时,它给了我们未定义的参考问题。我想使我的 CMakeList 能够从我的 JNI 调用任何 lapack 函数。有人可以帮助我使用 CMakeLists.txt 文件构建 lapack 模块。

4

0 回答 0