NCNN 移动端使用GPU坑
#错误信息 error: cannot use ‘throw’ with exceptions disabled error: use of typeid requires -frtti
Android: ncnn gpu运行配置方法
1、下载编译好的lib https://github.com/Tencent/ncnn/releases ncnn-android-vulkan-lib.zip
2、在CMakelists.txt 文件中加入 set(ncnn_DIR
L
I
B
R
A
R
Y
D
I
R
S
/
{LIBRARY_DIRS}/
LIBRARYD?IRS/{ANDROID_ABI}/lib/cmake/ncnn) find_package(ncnn REQUIRED)
3、修改 build.gradle
externalNativeBuild { cmake { cppFlags “-frtti -fexceptions -ljnigraphics " abiFilters ‘armeabi-v7a’, ‘arm64-v8a’ arguments “-DANDROID_STL=c++_shared”,”-DCMAKE_BUILD_TYPE=release" ,"-DANDROID_PLATFORM=android-24" // } }
4、编译,fuck 发现加入-frtti -fexceptions 选项后 怎么编译都还是报错. error: cannot use ‘throw’ with exceptions disabled error: use of typeid requires -frtti
解决办法: 编辑 .\ncnn-20211208-android-vulkan\cmake\ncnn\ncnn.cmake文件
# Create imported target ncnn
add_library(ncnn STATIC IMPORTED)
set_target_properties(ncnn PROPERTIES
INTERFACE_COMPILE_OPTIONS "-fno-rtti;-fno-exceptions"
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include/ncnn"
INTERFACE_LINK_LIBRARIES "Threads::Threads;Vulkan::Vulkan;\$<LINK_ONLY:glslang>;\$<LINK_ONLY:SPIRV>;android;jnigraphics;log"
INTERFACE_POSITION_INDEPENDENT_CODE "ON"
)
将 INTERFACE_COMPILE_OPTIONS “-fno-rtti;-fno-exceptions” 这句删掉。 编译成功~!!!耶耶耶
|