error: exception handling disabled, use -fexceptions to enable

本文介绍了解决Android平台移植过程中使用NDK编译时遇到的error:exceptionhandlingdisabled,use-fexceptionstoenable错误的方法。通过在Android.mk或Application.mk文件中添加-fexceptions来启用编译器的异常捕获。

转自:http://drovik.com/html/8410924155.html 

问题来源:

 

android平台移植过程中,在用NDK编译文件时出现error: exception handling disabled, use -fexceptions to enable。

 

问题解决:

此问题的出现是编译器的异常异常捕获被禁用了,需要在Android.mk文件中开启。在Android.mk文件中添加: LOCAL_CPPFLAGS += -fexceptions就可以了。或者在Application.mk文件中添加APP_CPPFLAGS += -fexceptions
也是可以的。

matt@V3SUB2204:~/v3s/thirdparty/v4l-utils-1.26.0$ meson configure build-armhf Core properties: Source dir /home/matt/v3s/thirdparty/v4l-utils-1.26.0 Build dir /home/matt/v3s/thirdparty/v4l-utils-1.26.0/build-armhf Main project options: Core options Current Value Possible Values Description ------------ ------------- --------------- ----------- auto_features auto [enabled, disabled, auto] Override value of all 'auto' features backend ninja [ninja, vs, vs2010, vs2012, vs2013, Backend to use vs2015, vs2017, vs2019, vs2022, xcode] buildtype debugoptimized [plain, debug, debugoptimized, Build type to use release, minsize, custom] cmake_prefix_path [] List of additional prefixes for cmake to search debug true [true, false] Debug default_library shared [shared, static, both] Default library type force_fallback_for [] Force fallback for those subprojects install_umask 0022 [preserve, 0000-0777] Default umask to apply on permissions of installed files layout mirror [mirror, flat] Build directory layout optimization 2 [0, g, 1, 2, 3, s] Optimization level pkg_config_path [] List of additional paths for pkg-config to search strip false [true, false] Strip targets on install unity off [on, off, subprojects] Unity build unity_size 4 >=2 Unity block size warning_level 1 [0, 1, 2, 3] Compiler warning level to use werror false [true, false] Treat warnings as errors wrap_mode default [default, nofallback, nodownload, Wrap mode forcefallback, nopromote] build.cmake_prefix_path [] List of additional prefixes for cmake to search build.pkg_config_path [] List of additional paths for pkg-config to search Backend options Current Value Possible Values Description --------------- ------------- --------------- ----------- backend_max_links 0 >=0 Maximum number of linker processes to run or 0 for no limit Base options Current Value Possible Values Description ------------ ------------- --------------- ----------- b_asneeded true [true, false] Use -Wl,--as-needed when linking b_colorout always [auto, always, never] Use colored output b_coverage false [true, false] Enable coverage tracking. b_lto false [true, false] Use link time optimization b_lto_threads 0 Use multiple threads for Link Time Optimization b_lundef true [true, false] Use -Wl,--no-undefined when linking b_ndebug false [true, false, if-release] Disable asserts b_pch true [true, false] Use precompiled headers b_pgo off [off, generate, use] Use profile guided optimization b_pie false [true, false] Build executables as position independent b_sanitize none [none, address, thread, undefined, Code sanitizer to use memory, address,undefined] b_staticpic true [true, false] Build static libraries as position independent Compiler options Current Value Possible Values Description ---------------- ------------- --------------- ----------- c_args [] Extra arguments passed to the c compiler c_link_args [] Extra arguments passed to the c linker c_std gnu99 [none, c89, c99, c11, gnu89, gnu99, C language standard to use gnu11] cpp_args [] Extra arguments passed to the cpp compiler cpp_debugstl false [true, false] STL debug mode cpp_eh default [none, default, a, s, sc] C++ exception handling type. cpp_link_args [] Extra arguments passed to the cpp linker cpp_rtti true [true, false] Enable RTTI cpp_std gnu++11 [none, c++98, c++03, c++11, c++14, C++ language standard to use c++17, c++1z, c++2a, c++20, gnu++03, gnu++11, gnu++14, gnu++17, gnu++1z, gnu++2a, gnu++20] build.c_args [] Extra arguments passed to the c compiler build.c_link_args [] Extra arguments passed to the c linker build.c_std none [none, c89, c99, c11, c17, c18, c2x, C language standard to use gnu89, gnu99, gnu11, gnu17, gnu18, gnu2x] build.cpp_args [] Extra arguments passed to the cpp compiler build.cpp_debugstl false [true, false] STL debug mode build.cpp_eh default [none, default, a, s, sc] C++ exception handling type. build.cpp_link_args [] Extra arguments passed to the cpp linker build.cpp_rtti true [true, false] Enable RTTI build.cpp_std none [none, c++98, c++03, c++11, c++14, C++ language standard to use c++17, c++1z, c++2a, c++20, gnu++03, gnu++11, gnu++14, gnu++17, gnu++1z, gnu++2a, gnu++20] Directories Current Value Possible Values Description ----------- ------------- --------------- ----------- bindir bin Executable directory datadir share Data file directory includedir include Header file directory infodir share/info Info page directory libdir lib Library directory libexecdir libexec Library executable directory localedir share/locale Locale data directory localstatedir /var Localstate data directory mandir share/man Manual page directory prefix /usr Installation prefix sbindir sbin System executable directory sharedstatedir /var/lib Architecture-independent data directory sysconfdir /etc Sysconf data directory Testing options Current Value Possible Values Description --------------- ------------- --------------- ----------- errorlogs true [true, false] Whether to print the logs from failing tests stdsplit true [true, false] Split stdout and stderr in test logs Project options Current Value Possible Values Description --------------- ------------- --------------- ----------- bpf auto [enabled, disabled, auto] Enable IR BPF decoders doxygen-doc disabled [enabled, disabled, auto] Generate doxygen project documentation doxygen-html true [true, false] Generate doxygen plain HTML documentation doxygen-man false [true, false] Generate doxygen manual pages gconv auto [enabled, disabled, auto] Enable compilation of gconv modules gconvsysdir Set system gconv directory (default is to autodetect) jpeg disabled [enabled, disabled, auto] jpeg libdvbv5 disabled [enabled, disabled, auto] Enable libdvbv5 compilation libv4l1subdir libv4l Set libv4l1 library subdir libv4l2subdir libv4l Set libv4l2 library subdir libv4lconvertsubdir libv4l Set libv4lconvert library subdir qv4l2 auto [enabled, disabled, auto] Enable qv4l2 compilation qvidcap auto [enabled, disabled, auto] Enable qvidcap compilation systemdsystemunitdir Set systemd system unit directory udevdir Set udev directory v4l-plugins true [true, false] V4L plugin support v4l-utils true [true, false] Enable v4l-utils compilation v4l-wrappers true [true, false] V4L wrappers support v4l2-compliance-32 false [true, false] Enable v4l2-compliance-32 compilation (for debugging purposes only) v4l2-compliance-libv4l true [true, false] Enable use of libv4l in v4l2-compliance v4l2-ctl-32 false [true, false] Enable v4l2-ctl-32 compilation (for debugging purposes only) v4l2-ctl-libv4l true [true, false] Enable use of libv4l in v4l2-ctl v4l2-ctl-stream-to true [true, false] Enable use of --stream-to in v4l2-ctl v4l2-tracer auto [enabled, disabled, auto] Enable v4l2-tracer compilation
最新发布
07-04
<think>我们遇到了一个特定的编译错误:`unknownwarningoption'-Wno-nan-infinity-disabled'[-Werror,-Wunknown-warning-option]`。这个错误发生在UE5安卓打包过程中,因为编译器不识别`-Wno-nan-infinity-disabled`这个警告选项,而我们的构建配置中又使用了`-Werror`(将警告视为错误),所以导致编译失败。根据引用[1]和[2]中提到的类似问题(将警告视为错误导致编译失败),我们可以采用类似的解决思路:将不支持的警告选项从编译标志中移除,或者将其转换为编译器支持的选项。但这里的问题是,这个警告选项本身是未知的,所以我们需要找到在UE5的安卓打包流程中如何修改编译标志。具体步骤:1.**定位问题**:错误信息明确指出是`-Wno-nan-infinity-disabled`这个选项不被识别。这个选项可能是由UE5引擎的某个模块或第三方库引入的。我们需要找到在哪里添加了这个编译选项。2.**修改编译标志**:参考引用[1]中提到的“万能公式”,将不支持的警告选项禁用。但注意,这里我们无法直接修改Android.bp或Android.mk,因为UE5使用的是自己的构建系统(通过UnrealBuildTool和UAT)。我们需要在UE5项目的配置文件中进行修改。3.**UE5中的修改位置**:-在UE5中,我们可以通过修改项目的`.Build.cs`文件(针对特定模块)或全局的引擎配置文件来调整编译选项。-但是,由于这个错误发生在安卓打包阶段,更可能是在NDK的编译选项中。我们可以在项目的`Platform`设置中调整安卓的编译标志。4.**具体操作**:-**方案一(推荐)**:在项目的构建配置中移除这个不支持的警告选项,或者将其替换为等效的、NDK支持的选项。-打开项目,进入`Edit->ProjectSettings->Platforms->Android`。-在`Build`部分,找到`ExtraCompilerFlags`(额外编译器标志)和`ExtraLinkerFlags`(额外链接器标志)。-在`ExtraCompilerFlags`中添加:`-Wno-unknown-warning-option`。这个选项的作用是让编译器忽略未知的警告选项,这样即使遇到不认识的警告选项也不会报错(因为-Werror)。但是注意,我们这里需要移除或覆盖`-Wno-nan-infinity-disabled`,但更直接的方法是让编译器忽略未知的警告选项。我们可以添加:```-Wno-unknown-warning-option```这样,当编译器遇到不认识的警告选项时,不会将其视为错误。-注意:这个方案可能会隐藏其他未知警告选项带来的问题,但可以解决当前问题。-**方案二**:找到添加`-Wno-nan-infinity-disabled`的地方并移除它。这可能需要修改引擎代码或插件代码,因为UE5的源码中可能会设置一些编译选项。我们可以搜索整个引擎目录和项目目录,查找包含`-Wno-nan-infinity-disabled`的文件,然后将其删除。但这种方法风险较大,因为修改引擎可能会影响其他项目。-**方案三**:升级NDK版本。这个警告选项可能是较新版本的编译器才支持的,而我们的NDK版本可能较旧。因此,我们可以尝试升级NDK到UE5推荐的版本(查看UE5文档中推荐的NDK版本)。在`ProjectSettings->Platforms->AndroidSDK`中设置正确的NDK路径,并确保NDK版本符合要求。5.**验证**:修改后重新打包,观察错误是否消失。6.**备选方案**:如果以上方法无效,我们可以尝试在打包命令中添加参数来覆盖编译选项。例如,在UAT(UnrealAutomationTool)命令中添加额外的参数。但这种方法需要修改打包脚本,比较复杂。**总结步骤**:1.尝试在项目设置的Android平台中的`ExtraCompilerFlags`里添加`-Wno-unknown-warning-option`。2.如果不行,检查NDK版本并升级到UE5推荐的版本。3.如果仍然不行,尝试在引擎或项目代码中搜索`-Wno-nan-infinity-disabled`并移除(不推荐,除非你确定它的来源且可以移除)。注意:在修改NDK版本时,请参考UE5官方文档中关于安卓平台要求的NDK版本,避免使用不兼容的版本。引用[1]和[2]提供了解决类似问题的思路(将警告视为错误的处理方式),但具体到我们的错误,我们需要处理的是未知的警告选项。因此,添加`-Wno-unknown-warning-option`是一个合理的解决方案。根据引用[3],我们看到有时头文件缺失也会导致编译失败,但我们的错误不是头文件缺失,所以可以排除。最后,如果上述方法都不能解决问题,可能需要查看完整的日志,确定这个警告选项是由哪个模块引入的,然后针对该模块进行修改。---###操作步骤总结1.**打开项目设置**:-在UnrealEditor中,点击`Edit->ProjectSettings`。-选择`Platforms->Android`。2.**修改额外编译器标志**:-在`Build`部分,找到`ExtraCompilerFlags`。-添加:`-Wno-unknown-warning-option`(注意:如果有多个标志,用空格隔开)。-保存设置。3.**重新打包**:-尝试重新打包安卓项目。4.**如果问题仍然存在**:-检查并更新NDK版本到UE5推荐的版本(例如NDKr21e或r25b,具体参考UE5版本要求)。-在`ProjectSettings->Platforms->AndroidSDK`中设置正确的NDK路径。5.**如果还是失败**:-在引擎和项目目录中搜索`-Wno-nan-infinity-disabled`,找到来源并移除(谨慎操作)。---###§§相关问题§§1.如何修改UE5项目的安卓编译标志?2.UE5安卓打包推荐使用哪个版本的NDK?3.如何解决UE5打包中其他未知的编译选项错误?4.在UE5中如何查看完整的打包日志?</think>### 解决 UE5 安卓打包错误:`unknown warning option '-Wno-nan-infinity-disabled'` 该错误是由于编译器无法识别 `-Wno-nan-infinity-disabled` 警告选项,同时启用了 `-Werror`(将警告视为错误)导致的。以下是具体解决方案: --- #### **解决方法** 1. **禁用未知警告选项**(推荐) 参考引用[1][2]的思路,将未知警告选项转换为编译器可识别的忽略格式: ```ini [Platform.Android] ; 在 DefaultEngine.ini 中添加以下配置 AdditionalCompilerArguments = -Wno-unknown-warning-option ``` **作用**: - `-Wno-unknown-warning-option` 会忽略所有未知的警告选项 - 阻止 `-Werror` 将未知警告视为致命错误[^1][^2] 2. **移除问题选项**(彻底方案) 检查项目中是否有代码或插件显式添加了 `-Wno-nan-infinity-disabled`: - 搜索整个项目目录(含插件)的 `.Build.cs` 文件 - 移除类似代码: ```csharp // 在模块的 Build.cs 文件中 PublicDefinitions.Add("CompilerArguments=-Wno-nan-infinity-disabled"); ``` 3. **更新 NDK 版本** 旧版 NDK 可能不支持此选项: - 在 `Project Settings > Android SDK` 中切换到 UE5 官方推荐的 NDK 版本 - UE5.3+ 推荐使用 **NDK r25b** 或更高版本 4. **临时禁用 `-Werror`** **(不推荐,仅用于验证)** 在 `AndroidToolChain.cs` 中注释掉 `-Werror`: ```csharp // 路径:Engine/Source/Programs/UnrealBuildTool/Platform/Android/AndroidToolChain.cs // 查找以下行并注释 // Arguments += " -Werror"; ``` --- #### **配置修改示例** 在 `Config/DefaultEngine.ini` 中添加: ```ini [Platform.Android] AdditionalCompilerArguments = -Wno-unknown-warning-option AndroidSDKDirectory = D:/Android/sdk AndroidNDKDirectory = D:/Android/ndk_r25b ; 更新NDK路径 ``` --- #### **根本原因分析** 1. **选项兼容性问题** `-Wno-nan-infinity-disabled` 是较新的 Clang 选项,旧版 Android NDK 的编译器可能不支持[^1]。 2. **警告即错误机制** UE5 默认启用 `-Werror`,任何警告(包括未知选项)都会中断编译[^2]。 3. **第三方插件引入** 某些插件可能添加了非标准的编译选项。 > ⚠️ 若问题出现在引擎源码编译阶段,需在 `BuildConfiguration.xml` 中添加 `-Wno-unknown-warning-option`。 --- ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值