在Android中包括升压C ++库 [英] Include Boost C++ library in android

查看:143
本文介绍了在Android中包括升压C ++库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图结婚升压和Android在Windows上很长一段时间,并试图很多办法,但仍然没有运气。我想要使​​用Boost库在Android中的示例程序。我下面这个教程<一个href="http://www.$c$cxperiments.com/android/2011/05/tips-tricks-building-boost-with-ndk-r5/">here.

I have been trying to marry Boost and android on windows for long time and tried lot of approaches but still no luck. I want to make a sample program using Boost library in android. I am following this tutorial here.

由于本教程建议我遵守了我升压lib目录中的 **(Android的NDK)\来源\ boost_1_44_0 ** 成功编译了。

As this tutorial suggested i have kept my Boost lib in **(Android NDK)\sources\boost_1_44_0** compiled it successfully.

这时我犯了一个 Android.mk 文件中的来源/ boost_1_44_0 并取得我想要使用的每个库的进入。在这种情况下的lib。文件的 libboost_date_time-GCC-MT-S-1_44.a 在现有的 boost_1_44_0 /安卓/ lib目录/
这里是 Android.mk 文件的内容。

Then i made an Android.mk file inside sources/boost_1_44_0 and made the entry of each library which i want to use. In this case lib. file is libboost_date_time-gcc-mt-s-1_44.a available in boost_1_44_0/android/lib/
Here is the content of Android.mk file.

LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:= boost_date
LOCAL_SRC_FILES:= boost_1_44_0/android/lib/libboost_date_time-gcc-mt-s-1_44.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(PREBUILT_STATIC_LIBRARY) 

现在,下一步是使 Android.mk 文件在我的项目目录,里面的 JNI 文件夹中。(这是创建一个共享库)。下面是它的内容。

Now the next step is to make an Android.mk file in my project directory, inside jni folder.(this is to create a shared library.). Here are its contents.

LOCAL_PATH := $(call my-dir)
 include $(call all-subdir-makefiles)

include $(CLEAR_VARS)

# Here we give our module name and source file(s)
LOCAL_LDLIBS := -llog -ldl
LOCAL_MODULE    := ndkfoo
LOCAL_SRC_FILES := ndkfoo.cpp
LOCAL_STATIC_LIBRARIES := boost_date
include $(BUILD_SHARED_LIBRARY)
$(call import-module,boost_1_44_0) 

下面是Application.mk文件放在同一位置,里面的 JNI 文件夹。是Application.mk文件的内容如下:

Here is the Application.mk file placed on the same location, inside jni folder. Contents of Application.mk file are as follows:

APP_STL      = gnustl_static #(or APP_STL = stlport_static as required)
APP_CPPFLAGS = -fexceptions  

最后,这里是我的 ndkfoo.cpp 文件

#include <string.h>
#include <jni.h>
#include <stdio.h>
#include <boost/date_time.hpp>

using namespace boost::gregorian;

void Java_com_ndkfoo_NdkfooActivity_invokeNativeFunction(JNIEnv* env, jobject javaThis) {
    date weekstart(2002,Feb,1);

}

此程序可能是不正确的,但问题是,它不承认任何boost头文件或功能。而我总是得到编译错误。

this program might be incorrect but the problem is that it does not recognize any boost headers or function. and i always get compilation error.

有我丢失的东西或做错误?任何帮助将是非常美联社preciated。

Is there something i am missing or doing incorrectly? Any help would be really appreciated.

编辑: 这个问题包含了一切你需要包括Boost库中的机器人。欲了解更多的技巧来看看我的回答如下。希望这也会为你工作。

感谢。

推荐答案

我的提问载有包括Boost库在Android中几乎完全步骤。但还是有,你应该记住,而这一工作的一些要点。

My question contained almost complete steps for including BOOST library in android. But still there are some important points you should remember while working with this.

  • 删除自动生成的 OBJ LIB 取值夹中的每个时间才能编译本地code。

  • Delete auto generated obj and libs folder Each time before you compile your native code.

如果你打算写你的本地code在C ++中,添加 LOCAL_CPP_EXTENSION:=的.cpp 您Android.mk( JNI / Android.mk )的文件。

If you are going to write your native code in C++, add LOCAL_CPP_EXTENSION := .cpp to your Android.mk(jni/Android.mk) file.

如果你要code在C ++中,把你所有的CPP code里面的的externC{}

if you are going to code in C++, put your all cpp code inside extern "C" {}.

外部C {/ * CPP code * /}

不要放弃,要有耐心,并且不断尝试;)

Dont give up, Be patient and keep trying.;).

这篇关于在Android中包括升压C ++库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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