最近,我使用 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/