NDK 编译protoc buf lite心得

来源:互联网 发布:mac我的所有文件 乱 编辑:程序博客网 时间:2024/06/10 19:08

首先感谢 http://blog.sina.com.cn/s/blog_632dcf7501011us2.html 和http://blog.sina.com.cn/s/blog_632dcf7501012bo0.html 给予了我很大的帮助。说说自己在编译过程中遇到的一些问题以及处理方法。

我的编译环境为 windows8 + NDK r8e, protoc buf 版本为2.5.0。

首先将protoc buf 目录里的\protobuf-2.5.0\src\google目录下的所有文件拷贝到jni目录下。目录结构图如下

然后将protobuf-2.5.0\vsprojects目录下的config.h文件拷贝到jni/google/protobuf/目录下。

配置android.mk,其详细内容如下

[html] view plaincopy
  1. # Copyright (C) 2009 The Android Open Source Project  
  2. #  
  3. # Licensed under the Apache License, Version 2.0 (the "License");  
  4. # you may not use this file except in compliance with the License.  
  5. # You may obtain a copy of the License at  
  6. #  
  7. #      http://www.apache.org/licenses/LICENSE-2.0  
  8. #  
  9. # Unless required by applicable law or agreed to in writing, software  
  10. # distributed under the License is distributed on an "AS IS" BASIS,  
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
  12. # See the License for the specific language governing permissions and  
  13. # limitations under the License.  
  14. #  
  15. LOCAL_PATH:= $(call my-dir)  
  16.   
  17. include $(CLEAR_VARS)  
  18.   
  19. LOCAL_CPPFLAGS += -frtti  
  20.   
  21. LOCAL_MODULE    :libnative  
  22.   
  23. LOCAL_CPP_EXTENSION := .cc .cpp  
  24.   
  25. #LOCAL_CPPFLAGS += -fexceptions  
  26. #LOCAL_CFLAGS    := -Werror  
  27. LOCAL_SRC_FILES :=  NativeEntry.cpp \  
  28.                                         google/protobuf/io/coded_stream.cc \  
  29.                                         google/protobuf/stubs/common.cc \  
  30.                                         google/protobuf/extension_set.cc \  
  31.                                         google/protobuf/message_lite.cc \  
  32.                                         google/protobuf/stubs/once.cc \  
  33.                                         google/protobuf/repeated_field.cc \  
  34.                                         google/protobuf/stubs/stringprintf.cc \  
  35.                                         google/protobuf/wire_format_lite.cc \  
  36.                                         google/protobuf/io/zero_copy_stream.cc \  
  37.                                         google/protobuf/io/zero_copy_stream_impl_lite.cc \  
  38.   
  39.               
  40. LOCAL_C_INCLUDES += . \  
  41.                                         $(LOCAL_PATH)/google \  
  42.                                         $(LOCAL_PATH)/google/protobuf \  
  43.               
  44. LOCAL_LDLIBS    := -llog -ldl  -lgcc -pthread \  
  45.                                 D:/progrome_tools/adt-bundle-windows-x86_64/android-ndk-r8e-windows-x86_64/android-ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi/libgnustl_static.a  
  46.   
  47. ifndef NDK_ROOT  
  48. include external/stlport/libstlport.mk  
  49. endif  
  50.   
  51. include $(BUILD_SHARED_LIBRARY)  

接下来配置Application.mk

[html] view plaincopy
  1. # The ARMv7 is significanly faster due to the use of the hardware FPU  
  2. APP_ABI :armeabi armeabi-v7a  
  3. APP_PLATFORM :android-7  
  4. APP_STL :gnustl_static  
然后修改config.h,注意网上有人建议不用修改config.h文件而是把backward_warning.h文件include进来.如果这样在编译的时候还是警告该文件以后的版本将不再使用。所以这种方式还是不可取,还是老老实实的修改config.h文件比较好。其config.h的文件内容如下

[html] view plaincopy
  1. /* protobuf config.h for MSVC.  On other platforms, this is generated  
  2.  * automatically by autoheader / autoconf / configure. */  
  3.   
  4. /* the location of <hash_map> */  
  5. //#define HASH_MAP_H <hash_map>  
  6.   
  7. /* the namespace of hash_map/hash_set */  
  8. // Apparently Microsoft decided to move hash_map *back* to the std namespace  
  9. // in MSVC 2010:  
  10. //   http://blogs.msdn.com/vcblog/archive/2009/05/25/stl-breaking-changes-in-visual-studio-2010-beta-1.aspx  
  11. // TODO(kenton):  Use unordered_map instead, which is available in MSVC 2010.  
  12. #if _MSC_VER < 1310 || _MSC_VER >= 1600  
  13. #define HASH_NAMESPACE std  
  14. #else  
  15. #define HASH_NAMESPACE stdext  
  16. #endif  
  17.   
  18. /* the location of <hash_set> */  
  19. #define HASH_SET_H <ext/hash_set>  
  20. #define HASH_MAP_H <ext/hash_map>  
  21. //#define HASH_NAMESPACE _gnu_cxx  
  22.   
  23. /* define if the compiler has hash_map */  
  24. //#define HAVE_HASH_MAP 1  
  25.   
  26. /* define if the compiler has hash_set */  
  27. //#define HAVE_HASH_SET 1  
  28.   
  29. #define HAVE_PTHREAD 1  
  30.   
  31. /* define if you want to use zlib.  See readme.txt for additional  
  32.  * requirements. */  
  33. // #define HAVE_ZLIB 1  

接下就是在eclipse下配置ndk编译环境不需要cywin,具体方法请参见http://blog.csdn.net/maojudong/article/details/7261986


转贴:http://blog.csdn.net/chujiujiao/article/details/8986997

0 0