Android NDK 未定义对ASensorEventQueue_registerSensor的引用
Android NDK undefined reference to ASensorEventQueue_registerSensor
我尝试通过NDK注册传感器,直到我尝试使用ASensorEventQueue_registerSensor为止,它一直有效。我像下面的代码一样做:
#include <android/sensor.h>
[...]
auto status = ASensorEventQueue_registerSensor(accelerometerEventQueue, accelerometer, SENSOR_REFRESH_PERIOD_US,SENSOR_BATCH_REPORT_TIME);
[...]
我的CMakeList.txt看起来像
cmake_minimum_required(VERSION 3.4.1)
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).
src/main/cpp/native-lib.cpp )
target_link_libraries( # Specifies the target library.
native-lib
android
log)
我可以使用ASensorEventQueue_enableSensor
或ASensorEventQueue_setEventRate
等函数,但由于未定义的引用错误,我在使用ASensorEventQueue_registerSensor
时无法运行该应用程序。
顺便说一下,我可以在包含的头文件中看到该函数,所以这应该不是问题。有没有人知道如何解决这个问题?
一种可能性是你错过了 liblog 和 libandroid 的find_library
。在target_link_libraries
之前添加以下内容:
find_library(android android)
find_library(log log)
但是我不确定是否需要。
另一种可能性是你的minSdkVersion
低于26。ASensorEventQueue_registerSensor
直到 O 才添加,因此除非您的minSdkVersion
至少为 26,否则无法链接它。
相关文章:
- 没有找到相关文章