NDK 下第一个boost asio 网络程序测试成功

环境配置:windowsxp  cygwin   android-ndk-r9c    boost_1_55_0 

1. 配置 boost_1_55_0\tools\build\v2\user-config.jam 文件,从网上搜的 自己改了下路径, NDK_ROOT 一定要设置正确

 import os ;
 
if [ os.name ] = CYGWIN || [ os.name ] = NT {
androidPlatform = windows ;
}
else if [ os.name ] = LINUX {
androidPlatform = linux-x86_64 ;
}
else if [ os.name ] = MACOSX {
androidPlatform = darwin-x86 ;
}
 
modules.poke : NO_BZIP2 : 1 ;
NDK_ROOT = D:/android-ndk-r9c ;
using gcc : android4.6 : $(NDK_ROOT)/toolchains/arm-linux-androideabi-4.6/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-g++ :
<archiver>$(NDK_ROOT)/toolchains/arm-linux-androideabi-4.6/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-ar
<ranlib>$(NDK_ROOT)/toolchains/arm-linux-androideabi-4.6/prebuilt/$(androidPlatform)/bin/arm-linux-androideabi-ranlib
<compileflags>--sysroot=$(NDK_ROOT)/platforms/android-9/arch-arm
<compileflags>-I$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.6/include
<compileflags>-I$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/include
<compileflags>-DNDEBUG
<compileflags>-D__GLIBC__
<compileflags>-DBOOST_FILESYSTEM_VERSION=3
<compileflags>-lstdc++
<compileflags>-lgnustl_shared
<compileflags>-mthumb
<compileflags>-fno-strict-aliasing
<compileflags>-std=gnu++11
<compileflags>-O2
;

2. 运行 boost_1_55_0\bootstrap.bat   生成  b2.exe

 

3. cygwin 中 目录切换至 boost_1_55_0     cmd中输入
./b2 --without-python toolset=gcc-android4.6 --build-type=complete threading=multi threadapi=pthread link=static runtime-link=static target-os=linux --stagedir=android

.................................等待各个*a 静态库编译完成,下步 在android 开发环境eclipse 中测试 boost asio 网络库

4. 生成jni 测试函数

      Application.mk 内容

# Build both ARMv5TE and ARMv7-A machine code.
APP_ABI := armeabi armeabi-v7a
APP_STL := gnustl_static

LOCAL_WHOLE_STATIC_LIBRARIES += boost_system-gcc-mt-s-1_55
LOCAL_WHOLE_STATIC_LIBRARIES += boost_filesystem-gcc-mt-s-1_55
LOCAL_WHOLE_STATIC_LIBRARIES += boost_thread_pthread-gcc-mt-s-1_55
APP_CPPFLAGS += -frtti -fexceptions

    Android.mk 中内容

LOCAL_PATH := $(call my-dir)

#static预编译

include $(CLEAR_VARS)
LOCAL_MODULE:= boost_filesystem-gcc-mt-s-1_55
LOCAL_SRC_FILES:= libboost/libboost_filesystem-gcc-mt-s-1_55.a
include $(PREBUILT_STATIC_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE:= boost_system-gcc-mt-s-1_55
LOCAL_SRC_FILES:= libboost/libboost_system-gcc-mt-s-1_55.a
include $(PREBUILT_STATIC_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE:= boost_thread_pthread-gcc-mt-s-1_55
LOCAL_SRC_FILES:= libboost/libboost_thread_pthread-gcc-mt-s-1_55.a
include $(PREBUILT_STATIC_LIBRARY)

#static预编译结束

include $(CLEAR_VARS)

LOCAL_MODULE := MainActivity

LOCAL_SRC_FILES := MainActivity.cpp
LOCAL_SRC_FILES += file_client.cpp


ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
    LOCAL_CFLAGS := -DHAVE_NEON=1
  
endif
  

LOCAL_STATIC_LIBRARIES := cpufeatures
LOCAL_STATIC_LIBRARIES += boost_filesystem-gcc-mt-s-1_55
LOCAL_STATIC_LIBRARIES += boost_system-gcc-mt-s-1_55
LOCAL_STATIC_LIBRARIES += boost_thread_pthread-gcc-mt-s-1_55

LOCAL_LDLIBS := -llog

include $(BUILD_SHARED_LIBRARY)

$(call import-module,cpufeatures)

5.  NDK_BUILD 生成 so 动态库
6.  Android 中测试 ,别忘记在 Manifest中加   <uses-permission android:name="android.permission.INTERNET" />

 

 

期间遇到了许多问题,主要有1. thread库编译失败 2.  Android.mk 中配置失败,导致找不到*.a静态  中函数  3.  NDK_BUILD 编译时出错 

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值