c++ - 尝试使用 Android-NDK 生成 so 文件时,未在此范围内声明“runtime_error”

标签 c++ android-ndk g++ native

我阅读了以下帖子,但我认为它不适用于我的情况:runtime_error was not declared in this scope for g++ 4.1.2

我的问题几乎相同,但我正在尝试使用 Android-NDK (r8c) 编译一个文件,我检查了 NDK 是否有 stdexcept.h,它确实有。这是我的消息来源:

#include <stdexcept>

class RandomName : public std::runtime_error {
public:
  ...
};

这是我的 Android.mk 文件:

# File: Android.mk
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := interfacetest
LOCAL_SRC_FILES := file.cpp
LOCAL_CFLAGS    := -frtti

include $(BUILD_SHARED_LIBRARY)

我应该在 Android.mk 文件中添加一些行吗?

最佳答案

在文件 CPLUSPLUS-SUPPORT.html 中的最新 NDK 文档中对此有很好的解释,尽管我将在此处生成相关位。对于默认的系统 运行时,唯一提供的 header 是:

cassert cctype cerrno cfloat climits cmath csetjmp csignal cstddef
cstdint cstdio cstdlib cstring ctime cwchar new stl_pair.h typeinfo
utility

从 NDK 版本 8 开始,唯一支持异常的运行时是 gnuSTL,您可以通过将以下内容添加到您的 Application.mk 而不是 Android.mk 来静态链接它:

APP_STL := gnustl_static

即便如此,您还需要一个额外的步骤:

The NDK toolchain supports C++ exceptions, since NDK r5, however all C++ sources are compiled with -fno-exceptions support by default, for compatibility reasons with previous releases.

To enable it, use the new LOCAL_CPP_FEATURES variable in your Android.mk, as in:

LOCAL_CPP_FEATURES += exceptions

关于c++ - 尝试使用 Android-NDK 生成 so 文件时,未在此范围内声明“runtime_error”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13950515/

相关文章:

c++ - Vulkan SDK 可再发行组件

c++ - 编写可能具有无效参数的构造函数的最佳方法

c++ - 使用 C++ QNetworkRequest 获取 HTTPS 网站内容

android - gradle> Task:app:externalNativeBuildDebug FAILED android_gradle_build.json(没有这样的文件或目录)

android-ndk - 如何从 native android 可执行文件获取对 JVM 的引用?

c++ - 静态库的全局变量的静态初始化和销毁​​不会在 g++ 中发生

c++ - QApplication::setWindowIcon 适用于 Windows XP,但不适用于 Windows 7

eclipse - Android NDK 中的多个(我的和第 3 方) native 库

c++ - 在不区分大小写的文件系统上模拟区分大小写

c++ - 创建 C++ Redis 模块 - "does not export RedisModule_OnLoad() symbol"