Reputation: 143
I created a small Test Project in the new Version of Android Studio to test the new c++ support.
I try to call a Function from a shared library. The Function is in an other .cpp File
Here is a Part of my CmakeLists.txt File:
add_library(JNI SHARED src/main/cpp/native-lib.cpp)
add_executable(testex src/main/cpp/test2.cpp)
INCLUDE_DIRECTORIES (src/main/cpp)
target_link_libraries(testex JNI)
The test2.h File:
class Test{
public:
int side;
intgetArea();
};
The test2.cpp File:
#include "test2.h"
int Test::getArea(){
return side*side;
}
And a Part of my native-lib.cpp File:
JNIEXPORT jstring JNICALL
.....(JNIEnv *env,jobject instance){
Test *test = new Test();
test->getArea();
.
.
.
I get these Error: error: undefined reference to 'Test::getArea()
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
I hope someone can help me :)
Upvotes: 2
Views: 1192
Reputation: 12583
It looks you are trying to test your native code. One feasible approach is to use googletest suite (https://cmake.org/cmake/help/v3.10/module/GoogleTest.html) for your JNI testing.
Here is the github reference about google test: https://github.com/google/googletest/blob/master/googletest/README.md
Upvotes: 0
Reputation: 1233
Android CMake support is to generate shared lib for Java code to load during the run-time; the shared lib could call other functions in other native libs ( shared or static ). Your usage model is not supported: android does not support native executable in jni framework.
Upvotes: 1