如何与And​​roid NDK和STLport的使用升压库(包括shared_ptr的) [英] How to use the boost library (including shared_ptr) with the Android NDK and STLport

查看:282
本文介绍了如何与And​​roid NDK和STLport的使用升压库(包括shared_ptr的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个多问题的答案,因为我已经想通了,至少尽可能干净编译库。对我来说,主要的问题是让shared_ptr的工作。

This is more of an answer than a question, because I've figured it out, at least as far as cleanly compiling the library. The main issue for me was to get shared_ptr working.

主料:

升压诉1.45.0

在<一的STLport的版本href=\"http://www.anddev.org/viewtopic.php?p=29939\">http://www.anddev.org/viewtopic.php?p=29939.

的NDK版本R4B。

路线:

在你的Andr​​oid.mk文件中加入:

In your Android.mk file add:

LOCAL_CFLAGS += -DBOOST_EXCEPTION_DISABLE -D_STLP_NO_EXCEPTIONS -DOS_ANDROID -D_STLP_USE_SIMPLE_NODE_ALLOC

删除通话时的STLport / STL / _string.h 613线__stl_throw_length_error。如果你喜欢,你可以使用_STLP_NO_EXCEPTIONS。

Remove the call to __stl_throw_length_error at line 613 of stlport/stl/_string.h. You can use _STLP_NO_EXCEPTIONS if you like.

编辑升压/升压/ smart_ptr / shared_ptr.hpp线261后摆脱呼叫提振:: throw_exception在shared_ptr的构造。我用的#ifndef BOOST_EXCEPTION_DISABLE绕法的整个身体。 (但请参阅下面的答案。)

Edit boost/boost/smart_ptr/shared_ptr.hpp after line 261 to get rid of the call to boost::throw_exception in the shared_ptr constructor. I used #ifndef BOOST_EXCEPTION_DISABLE around the entire body of the method. (But see the answer below.)

接下来,您需要提供一些缺少的部分。用下面创建一个头文件:

Next you need to supply some missing pieces. Create a header file with the following:

#ifdef OS_ANDROID

#include <exception>

namespace std
{
    struct bad_alloc : public exception { bad_alloc operator()(){}};
}

#endif

和一个精简的异常类源文件,以支持bad_alloc:

and a source file with a stripped-down exception class to support bad_alloc:

#ifdef OS_ANDROID

#include <exception>

namespace std
{
    exception::exception() {}
    exception::~exception() {}
    const char* exception::what() const {}
}

#endif

包含无论你是包括升压/ shared_ptr.hpp头。编译源代码,并将其添加到库中。

Include the header wherever you're including boost/shared_ptr.hpp. Compile the source and add it to your library.

推荐答案

原来,编译调试的库时,这种方法并不能完全工作。发布库编译-O2从而优化了一些infelicities,但调试库与-O0它揭示了一些额外的问题进行。此外,我是不是太高兴不必编辑升压文件。因此,与其他一些研究,我想出了以下的解决方案。

It turned out that this approach does not entirely work when compiling a debuggable library. The release library is compiled with -O2 which optimizes out some infelicities, but the debug library is done with -O0 which reveals some additional problems. Furthermore, I wasn't too happy about having to edit the boost files. So with some additional study, I've come up with the following solution.

首先,不要编辑任何提振文件。相反,添加以下std命名空间中的标题:

First, don't edit any of the boost files. Instead add the following to the header within the std namespace:

struct bad_cast : public exception {bad_cast operator()(){}};

接下来,添加下面的源文件:

Next add the following to the source file:

namespace boost
{
    void throw_exception(std::exception const&) {}
}

这现在编译和链接到应用程序中,即使与Android:在AndroidManifest.xml可调试=真。它不会在模拟器中运行,但它没有这样做之前,我可能包括该库。

This now compiles and links into the application even with android:debuggable="true" in AndroidManifest.xml. It doesn't run in the emulator, but then it wasn't doing that before I included this library either.

这篇关于如何与And​​roid NDK和STLport的使用升压库(包括shared_ptr的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆