无法在Android Studio中包含c++标准



我有一个Android Compose项目。现在我添加了C++,它与初始文件配合得很好

eazmath.cpp:

// Write C++ code here.
//
// Do not forget to dynamically load the C++ library into your application.
//
// For instance,
//
// In MainActivity.java:
//    static {
//       System.loadLibrary("eazmath");
//    }
//
// Or, in MainActivity.kt:
//    companion object {
//      init {
//         System.loadLibrary("eazmath")
//      }
//    }
#include <jni.h>
#include <string>
extern "C"
jstring Java_com_example_eazmath_expressionsimplifier_ExpressionSimplifier_test(JNIEnv *env,
          jobject caller)
{
std::string str = "Hey There!"; // Just for testing
return (*env).NewStringUTF(str.c_str());
}

但是,当我创建一个新的C++类并添加到项目中时,以下几行:

#include <jni.h>
#include <string>

正在显示一个错误:

未找到"文件名"文件

有人知道上面是什么吗?

我通过在CMakeLists.txt:中添加源文件解决了这个问题

add_library( # Sets the name of the library.
libname
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
cpp1.cpp cpp2.cpp cpp3.cpp ) # Do not separate these by commas!

最新更新