未找到Android Studio NDK iostream文件,无法在CMakeList中启用neon
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了未找到Android Studio NDK iostream文件,无法在CMakeList中启用neon相关的知识,希望对你有一定的参考价值。
我是使用NDK和CMake的新手,在编译我的C ++库时遇到了问题,android studio一直在编译它
错误:(28,2)错误:“未启用NEON支持”
错误:错误:此目标不支持'neon_vector_type'属性
错误:(17,15)致命错误:找不到'iostream'文件
我看到一些解决方案说我应该在Application.mk中添加APP_STL:= stlport_static
但是,我使用的是CMakeLists而不是Application.mk。
所以我在CMAKE_C_FLAGS上添加了-DANDROID_ARM_NEON = TRUE -DAPP_STL = stlport_static,但它仍然会产生相同的错误
这是我的CMakeLists
set (pathToProject /home/user/project)
set (pathToOpenCv /home/user/project/OpenCV330)
FILE(GLOB_RECURSE cppfiles src/main/cpp/src/*)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED on)
find_package(OpenMP)
add_definitions(-fPIC)
add_definitions(-fopenmp)
add_definitions(-Ofast)
add_definitions(-DANDROID_STL=c++_shared)
add_definitions(-flax-vector-conversions)
add_definitions(-fopenmp)
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fpermissive -DANDROID_ARM_NEON=TRUE -DAPP_STL=stlport_static")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
include_directories(${pathToProject}/app/src/main/cpp/src/include)
include_directories(${pathToOpenCv}/sdk/native/jni/include)
add_library(lib_opencv SHARED IMPORTED)
add_library(native-lib SHARED src/main/cpp/native-lib.cpp )
add_library(mylibrary SHARED ${cppfiles} )
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION ${pathToProject}/app/src/main/jniLibs/${ANDROID_ABI}/libopencv_java3.so)
find_library(log-lib log)
target_link_libraries(
native-lib
${log-lib}
lib_opencv
mylibrary
)
更新:
我还发现了另外1个编译消息,看起来像-std = c ++ 11在编译时实际上并未应用
[10/11] Building CXX object CMakeFiles/mylibrary.dir/src/main/cpp/src/yuv420sp.cpp.o
FAILED: /home/user/Downloads/android-ndk-r14b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=i686-none-linux-android --gcc-toolchain=/home/user/Downloads/android-ndk-r14b/toolchains/x86-4.9/prebuilt/linux-x86_64 --sysroot=/home/user/Downloads/android-ndk-r14b/platforms/android-24/arch-x86 -Dmylibrary_EXPORTS -I../../../../src/main/cpp/include -I/home/user/git/project/OpenCV-android-sdk3.3.0/sdk/native/jni/include -I../../../../src/main/cpp/build/include -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -Wa,--noexecstack -Wformat -Werror=format-security -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -Wa,--noexecstack -Wformat -Werror=format-security -O0 -fno-limit-debug-info -O0 -fno-limit-debug-info -fPIC -MD -MT CMakeFiles/mylibrary.dir/src/main/cpp/src/object_wrap.c.o -MF CMakeFiles/mylibrary.dir/src/main/cpp/src/object_wrap.c.o.d -o CMakeFiles/mylibrary.dir/src/main/cpp/object_wrap.c.o -c /home/user/git/project/app/src/main/cpp/object_wrap.c
In file included from /home/user/git/project/app/src/main/cpp/src/object_wrap.c:209:
/home/user/git/project/app/src/main/cpp/src/object.h:17:10: fatal error: 'iostream' file not found
#include <iostream>
^
还尝试在app gradle中设置标志,仍然无法正常工作
externalNativeBuild {
cmake {
cppFlags "-std=c++11", "-Wno-error=format-security"
arguments "-DANDROID_STL=gnustl_static", "-DANDROID_ARM_NEON=TRUE"
}
}
如果我设置-DANDROID_STL = stlport_static,它将再给出两个错误
错误:(25,10)致命错误:找不到'thread'文件
错误:(424,14)致命错误:找不到'array'文件
在gradle中更改为gcc工具链后,问题解决了。
arguments "-DANDROID_TOOLCHAIN=gcc","-DANDROID_ARM_NEON=TRUE" ,"-DANDROID_STL_FORCE_FEATURES=OFF"
cppFlags "-std=gnu++11", "-Wno-error=format-security"
以上是关于未找到Android Studio NDK iostream文件,无法在CMakeList中启用neon的主要内容,如果未能解决你的问题,请参考以下文章
Android Studio NDK链接器错误未定义引用'cv :: _ OutputArray :: _ OutputArray(cv :: Mat&)'
Android Studio编译开源项目(含NDK开发)常见报错
Android Studio NDK开发-JNI调用Java方法
jni/ndk: android studio external tool 自定义工具(Javah/ndk-build命令)