且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

【错误记录】Visual Studio 中编译 NDK 报错 ( error : cannot use ‘throw‘ with exceptions disabled )

更新时间:2021-09-17 23:59:52

文章目录

一、报错信息

二、解决方案





一、报错信息


使用 Visual Studio 2019 编译 Android NDK 项目 , 报错如下 :


已启动生成…
1>------ 已启动生成: 项目: native, 配置: Debug ARM ------
1>ANDROID_HOME=D:\\Microsoft\AndroidSDK\25
1>ANT_HOME=D:\001_Develop\017_Microsoft Visual Studio\2019\Community\Apps\apache-ant-1.9.3
1>JAVA_HOME=C:\Program Files\Android\jdk\microsoft_dist_openjdk_1.8.0.25
1>NDK_ROOT=D:\\Microsoft\AndroidNDK64\android-ndk-r16b
1>json_reader.cpp
1>json\json_reader.cpp(1129,14): error : cannot use 'throw' with exceptions disabled
1>    if (!ok) throw std::runtime_error(reader.getFormatedErrorMessages());
1>             ^
1>1 error generated.
1>已完成生成项目“native.vcxproj”的操作 - 失败。
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========



【错误记录】Visual Studio 中编译 NDK 报错 ( error : cannot use ‘throw‘ with exceptions disabled )





二、解决方案


在项目属性中设置 " 启动 C++ 异常 " 项为 " 是 ( -fexception ) " 选项 ;


【错误记录】Visual Studio 中编译 NDK 报错 ( error : cannot use ‘throw‘ with exceptions disabled )



如果使用 Android.mk 构建项目 , 可以添加 LOCAL_CPP_FEATURES += exceptions 或 LOCAL_CPPFLAGS += -fexceptions 配置 ;


也可以在 Application.mk 中配置 APP_CPPFLAGS += -fexceptions ;