我阅读了以下帖子,但我认为它不适用于我的情况: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/