Android C++ 构建错误 '__cxa_begin_catch'

标签 android c++ exception

最近,我使用 Android SOURCE 4.04,我想将我自己的库添加到外部目录。

我遇到了一个问题: 当我的 C++ 代码使用“C++ 异常函数”时,它构建失败。

我写了一个简单的c++测试代码,也失败了。

=========构建错误的日志:

test.cpp:14: undefined reference to `__cxa_begin_catch'
test.cpp:14: undefined reference to `__cxa_end_catch'
out/target/product/bcm7231/obj/EXECUTABLES/test_intermediates/test.o:(.data.rel.ro._ZTISt9exception[_ZTISt9exception]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
out/target/product/bcm7231/obj/EXECUTABLES/test_intermediates/test.o:(.data.DW.ref.__gxx_personality_v0[DW.ref.__gxx_personality_v0]+0x0): undefined reference to `__gxx_personality_v0'

=============简单的C++测试如下:

//Test.cpp
#include <exception>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    cout << "hello world" << endl;
    // Test c++ exception
    int* myarray = NULL;
    try 
    {   
        myarray= new int[1024 * 128];
    }   
    catch (exception& e)
    {   
        cout << "Standard exception: " << e.what() << endl;
    }

    delete[] myarray;

    return 0;
}

============= Android.mk 如下:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES := test.cpp
LOCAL_C_INCLUDES := external/stlport/stlport \
                    bionic \
                    bionic/libstdc++
LOCAL_MODULE := test
LOCAL_MODULE_TAGS := optional

LOCAL_CPP_FEATURES += exceptions
LOCAL_CPPFLAGS :=  -fexceptions
LOCAL_SHARED_LIBRARIES := libstlport

include $(BUILD_EXECUTABLE)

有人知道吗? 我现在对此感到困惑。

最佳答案

在 AOSP 中构建系统时不支持 c++ 异常。

关于Android C++ 构建错误 '__cxa_begin_catch',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27374117/

相关文章:

c++ - 选择适当的FIFO数据结构

ruby - Rails 4 忽略错误/异常并继续

android - 我如何在android studio中写一个分数

android - Ebay API - 滚动加载更多项目加载相同的数据

c++ - 后备可变参数构造函数 - 为什么会这样?

c++ - throw, try {} catch {} 应该如何在现实世界中使用?

c++ - Windows默默捕捉到的异常,如何手动处理?

Android:如何将启动器图标放在第一个位置

android - 在android中的ui依赖项中添加brain tree drop时dex文件无法合并

c++ - visual studio 2008 express 需要很长时间才能在 Debug模式下运行 c++ 应用程序(小)