adding protobuf libraries

Good day.
I encountered with a problem in adding protobufs libraries in cocos2d-x project.

Error: “fatal error: google/protobuf/stubs/common.h: No such file or directory
compilation terminated.”

How can I resolve this problem?
Thank you in advance for your help

I tried to include /usr/include folder to the project. But then builder gave me a count of collisions. How can I avoid them?

In file included from /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/sys/limits.h:47:0, from /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/limits.h:86, from /usr/include/limits.h:125, from /home/georg/android/cocos2d_x/cocos2dx/support/data_support/ccCArray.h:50, from /home/georg/android/cocos2d_x/cocos2dx/cocoa/CCArray.h:28, from /home/georg/android/cocos2d_x/cocos2dx/base_nodes/CCNode.h:33, from /home/georg/android/cocos2d_x/cocos2dx/actions/CCActionInterval.h:30, from /home/georg/android/cocos2d_x/cocos2dx/include/cocos2d.h:42, from jni/../../Classes/AppDelegate.h:4, from jni/helloworld/main.cpp:1: /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/machine/limits.h:40:0: warning: "MB_LEN_MAX" redefined [enabled by default] /usr/include/limits.h:33:0: note: this is the location of the previous definition In file included from /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/sys/_types.h:40:0, from /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/_ctype.h:50, from /home/georg/android/android_ndk/sources/cxx-stl/gnu-libstdc++/libs/armeabi/4.6.3/include/bits/ctype_base.h:33, from /home/georg/android/android_ndk/sources/cxx-stl/gnu-libstdc++/include/4.6.3/bits/locale_facets.h:43, from /home/georg/android/android_ndk/sources/cxx-stl/gnu-libstdc++/include/4.6.3/bits/basic_ios.h:39, from /home/georg/android/android_ndk/sources/cxx-stl/gnu-libstdc++/include/4.6.3/ios:45, from /home/georg/android/android_ndk/sources/cxx-stl/gnu-libstdc++/include/4.6.3/istream:40, from /home/georg/android/android_ndk/sources/cxx-stl/gnu-libstdc++/include/4.6.3/sstream:39, from /home/georg/android/cocos2d_x/cocos2dx/label_nodes/CCLabelBMFont.h:38, from /home/georg/android/cocos2d_x/cocos2dx/include/cocos2d.h:95, from jni/../../Classes/AppDelegate.h:4, from jni/helloworld/main.cpp:1: /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/machine/_types.h:103:15: error: conflicting declaration 'typedef int __clock_t' /usr/include/bits/types.h:145:27: error: '__clock_t' has a previous declaration as 'typedef long int __clock_t' /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/machine/_types.h:106:15: error: conflicting declaration 'typedef int __time_t' /usr/include/bits/types.h:149:26: error: '__time_t' has a previous declaration as 'typedef long int __time_t' /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/machine/_types.h:107:15: error: conflicting declaration 'typedef int __timer_t' /usr/include/bits/types.h:161:27: error: '__timer_t' has a previous declaration as 'typedef void* __timer_t' In file included from /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/_ctype.h:50:0, from /home/georg/android/android_ndk/sources/cxx-stl/gnu-libstdc++/libs/armeabi/4.6.3/include/bits/ctype_base.h:33, from /home/georg/android/android_ndk/sources/cxx-stl/gnu-libstdc++/include/4.6.3/bits/locale_facets.h:43, from /home/georg/android/android_ndk/sources/cxx-stl/gnu-libstdc++/include/4.6.3/bits/basic_ios.h:39, from /home/georg/android/android_ndk/sources/cxx-stl/gnu-libstdc++/include/4.6.3/ios:45, from /home/georg/android/android_ndk/sources/cxx-stl/gnu-libstdc++/include/4.6.3/istream:40, from /home/georg/android/android_ndk/sources/cxx-stl/gnu-libstdc++/include/4.6.3/sstream:39, from /home/georg/android/cocos2d_x/cocos2dx/label_nodes/CCLabelBMFont.h:38, from /home/georg/android/cocos2d_x/cocos2dx/include/cocos2d.h:95, from jni/../../Classes/AppDelegate.h:4, from jni/helloworld/main.cpp:1: /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/sys/_types.h:43:19: error: conflicting declaration 'typedef __int32_t __dev_t' /usr/include/bits/types.h:134:25: error: '__dev_t' has a previous declaration as 'typedef __u_quad_t __dev_t' /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/sys/_types.h:49:20: error: conflicting declaration 'typedef __uint32_t __ino_t' /usr/include/bits/types.h:137:25: error: '__ino_t' has a previous declaration as 'typedef long unsigned int __ino_t' /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/sys/_types.h:50:15: error: conflicting declaration 'typedef long int __key_t' /usr/include/bits/types.h:155:25: error: '__key_t' has a previous declaration as 'typedef int __key_t' /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/sys/_types.h:54:20: error: conflicting declaration 'typedef __uint64_t __rlim_t' /usr/include/bits/types.h:146:26: error: '__rlim_t' has a previous declaration as 'typedef long unsigned int __rlim_t' /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/sys/_types.h:58:19: error: conflicting declaration 'typedef __int32_t __swblk_t' /usr/include/bits/types.h:154:27: error: '__swblk_t' has a previous declaration as 'typedef long int __swblk_t' /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/sys/_types.h:61:19: error: conflicting declaration 'typedef __int32_t __suseconds_t' /usr/include/bits/types.h:151:31: error: '__suseconds_t' has a previous declaration as 'typedef long int __suseconds_t' /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/sys/_types.h:70:3: error: conflicting declaration 'typedef union __mbstate_t __mbstate_t' /usr/include/wchar.h:95:3: error: '__mbstate_t' has a previous declaration as 'typedef struct __mbstate_t __mbstate_t' In file included from /home/georg/android/android_ndk/sources/cxx-stl/gnu-libstdc++/libs/armeabi/4.6.3/include/bits/ctype_base.h:33:0, from /home/georg/android/android_ndk/sources/cxx-stl/gnu-libstdc++/include/4.6.3/bits/locale_facets.h:43, from /home/georg/android/android_ndk/sources/cxx-stl/gnu-libstdc++/include/4.6.3/bits/basic_ios.h:39, from /home/georg/android/android_ndk/sources/cxx-stl/gnu-libstdc++/include/4.6.3/ios:45, from /home/georg/android/android_ndk/sources/cxx-stl/gnu-libstdc++/include/4.6.3/istream:40, from /home/georg/android/android_ndk/sources/cxx-stl/gnu-libstdc++/include/4.6.3/sstream:39, from /home/georg/android/cocos2d_x/cocos2dx/label_nodes/CCLabelBMFont.h:38, from /home/georg/android/cocos2d_x/cocos2dx/include/cocos2d.h:95, from jni/../../Classes/AppDelegate.h:4, from jni/helloworld/main.cpp:1: /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/_ctype.h:88:40: error: expected initializer before '__pure' /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/_ctype.h:89:37: error: expected initializer before '__pure' /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/_ctype.h:90:37: error: expected initializer before '__pure' /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/_ctype.h: In function 'int __maskrune(__ct_rune_t, long unsigned int)': /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/_ctype.h:116:58: error: '___runetype' was not declared in this scope /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/_ctype.h: At global scope: /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/_ctype.h:140:1: error: expected primary-expression before '_c' /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/_ctype.h:140:1: error: expected ')' before '_c' /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/_ctype.h:146:1: error: expected ']' before 'static' /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/_ctype.h:146:1: error: expected ')' before 'static' /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/_ctype.h: In function '__ct_rune_t __tolower(__ct_rune_t)': /home/georg/android/android_ndk/platforms/android-14/arch-arm/usr/include/_ctype.h:163:56: error: '___tolower' was not declared in this scope make: *** [obj/local/armeabi/objs-debug/game_shared/helloworld/main.o] Ошибка 1

if xcode,
You need to add header file search path,
Add protobuf/src directory.:slight_smile:

I using linux.
As I understand I need to create STATIC_MODULE for using any static library .a? Am I right?

Yes, use makefile

How I have to include libprotobuf.a? Copy it in jni directory?
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS)

LOCAL_MODULE := libprotobuf LOCAL_SRC_FILES := libprotobuf.a
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes

include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE := game_shared

LOCAL_MODULE_FILENAME := libgame

LOCAL_CPP_EXTENSION := .cpp \ .cc

LOCAL_SRC_FILES := helloworld/main.cpp \ ../../Classes/AppDelegate.cpp \ ../../Classes/HelloWorldScene.cpp \ ../../Classes/PromowallLibrary/protocol.pb.cc

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \ $(LOCAL_PATH)

LOCAL_STATIC_LIBRARIES := libprotobuf LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static

include $(BUILD_SHARED_LIBRARY)

$(call import-module,CocosDenshion/android) $(call import-module,cocos2dx)

I get errors like that:
@
/home/ivan/android/android_ndk/toolchains/arm-linux-androideabi-4.6.3/prebuilt/linux-x86/bin/…/lib/gcc/arm-linux-androideabi/4.6.3/…/…/…/…/arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi/libprotobuf.a(common.o): incompatible target
/home/ivan/android/android_ndk/toolchains/arm-linux-androideabi-4.6.3/prebuilt/linux-x86/bin/…/lib/gcc/arm-linux-androideabi/4.6.3/…/…/…/…/arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi/libprotobuf.a(generated_message_util.o): incompatible target
/home/ivan/android/android_ndk/toolchains/arm-linux-androideabi-4.6.3/prebuilt/linux-x86/bin/…/lib/gcc/arm-linux-androideabi/4.6.3/…/…/…/…/arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi/libprotobuf.a(message_lite.o): incompatible target
@

fix problem ?

Yes, I solve the last problem. But now I have new one :slight_smile:

I have an Anrdoid application implemented with help of cocos2d-x engine. I linked protobuf library to the project and trying to SerializeToStrint() one proto-object:

@
ProtoMessage message;
message.set_app_id(1111);
@
@
message.set_hardware_id(“test string”);
std::string str;
message.SerializeToString(&str);
@

That’s builds fine, but when I trying to start application logcat send me next log:

09-14 10:26:51.748 13009 13009 I DEBUG : Build fingerprint: verizon/droid2we_vzw/cdma_droid2we:2.3.4/4.5.1_57_D2GA-59/120117:user/release-keys 09-14 10:26:51.748 13009 13009 I DEBUG : pid: 12996, tid: 13008 >>> com.karmicapps <<< 09-14 10:26:51.748 13009 13009 I DEBUG : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad 09-14 10:26:51.748 13009 13009 I DEBUG : r0 00000027 r1 deadbaad r2 a0000000 r3 00000000 09-14 10:26:51.748 13009 13009 I DEBUG : r4 00000001 r5 00000000 r6 81b15340 r7 0000a000 09-14 10:26:51.748 13009 13009 I DEBUG : r8 818d4ed1 r9 44df07c8 10 00100000 fp 00000001 09-14 10:26:51.748 13009 13009 I DEBUG : ip afd466c8 sp 45ac1df8 lr afd19239 pc afd15d08 cpsr 60000070 09-14 10:26:51.748 13009 13009 I DEBUG : d0 643a64696f72646e d1 6472656767756265 09-14 10:26:51.748 13009 13009 I DEBUG : d2 0049002e00690045 d3 0066007200750047 09-14 10:26:51.748 13009 13009 I DEBUG : d4 0000000000000000 d5 0000000100000000 09-14 10:26:51.748 13009 13009 I DEBUG : d6 000000000000f760 d7 0000000000000000 09-14 10:26:51.748 13009 13009 I DEBUG : d8 0000000000000000 d9 0000000000000000 09-14 10:26:51.756 13009 13009 I DEBUG : d10 0000000000000000 d11 0000000000000000 09-14 10:26:51.756 13009 13009 I DEBUG : d12 0000000000000000 d13 0000000000000000 09-14 10:26:51.756 13009 13009 I DEBUG : d14 0000000000000000 d15 0000000000000000 09-14 10:26:51.756 13009 13009 I DEBUG : d16 3fdd938000000280 d17 3fdfffffffffe114 09-14 10:26:51.756 13009 13009 I DEBUG : d18 3fe0000000000000 d19 3fe0000000000f76 09-14 10:26:51.756 13009 13009 I DEBUG : d20 0000000000000000 d21 3f872e5c54a96637 09-14 10:26:51.756 13009 13009 I DEBUG : d22 3e21e7c5992989f4 d23 bda8fae9be8838d4 09-14 10:26:51.756 13009 13009 I DEBUG : d24 3fc74721cad6b0ed d25 3fc39a09d078c69f 09-14 10:26:51.756 13009 13009 I DEBUG : d26 0000000000000000 d27 0000000000000000 09-14 10:26:51.756 13009 13009 I DEBUG : d28 0000000000000000 d29 0000000000000000 09-14 10:26:51.756 13009 13009 I DEBUG : d30 0000000000000000 d31 0000000000000000 09-14 10:26:51.756 13009 13009 I DEBUG : scr 20000012 09-14 10:26:51.756 13009 13009 I DEBUG : 09-14 10:26:51.803 13009 13009 I DEBUG : #00 pc 00015d08 /system/lib/libc.so 09-14 10:26:51.803 13009 13009 I DEBUG : #01 pc 00013674 /system/lib/libc.so 09-14 10:26:51.803 13009 13009 I DEBUG : #02 pc 0001453a /system/lib/libc.so 09-14 10:26:51.803 13009 13009 I DEBUG : #03 pc 000a45ec /data/data/com.karmicapps/lib/libprotobuf.so 09-14 10:26:51.803 13009 13009 I DEBUG : #04 pc 000a46d0 /data/data/com.karmicapps/lib/libprotobuf.so 09-14 10:26:51.803 13009 13009 I DEBUG : #05 pc 000445ac /data/data/com.karmicapps/lib/libprotobuf.so 09-14 10:26:51.803 13009 13009 I DEBUG : #06 pc 000445f6 /data/data/com.karmicapps/lib/libprotobuf.so 09-14 10:26:51.803 13009 13009 I DEBUG : #07 pc 00044616 /data/data/com.karmicapps/lib/libprotobuf.so 09-14 10:26:51.803 13009 13009 I DEBUG : #08 pc 000d51f8 /data/data/com.karmicapps/lib/libpromowall.so 09-14 10:26:51.803 13009 13009 I DEBUG : #09 pc 000d4ee4 /data/data/com.karmicapps/lib/libpromowall.so 09-14 10:26:51.803 13009 13009 I DEBUG : #10 pc 0001194c /system/lib/libc.so 09-14 10:26:51.803 13009 13009 I DEBUG : #11 pc 00011510 /system/lib/libc.so 09-14 10:26:51.803 13009 13009 I DEBUG : 09-14 10:26:51.803 13009 13009 I DEBUG : code around pc: 09-14 10:26:51.803 13009 13009 I DEBUG : afd15ce8 2c006824 e028d1fb b13368db c064f8df 09-14 10:26:51.803 13009 13009 I DEBUG : afd15cf8 44fc2401 4000f8cc 49124798 25002027 09-14 10:26:51.803 13009 13009 I DEBUG : afd15d08 f7f57008 2106ec72 edd6f7f6 460aa901 09-14 10:26:51.803 13009 13009 I DEBUG : afd15d18 f04f2006 95015380 95029303 e934f7f6 09-14 10:26:51.803 13009 13009 I DEBUG : afd15d28 462aa905 f7f62002 f7f5e940 2106ec5e 09-14 10:26:51.803 13009 13009 I DEBUG : 09-14 10:26:51.803 13009 13009 I DEBUG : code around lr: 09-14 10:26:51.803 13009 13009 I DEBUG : afd19218 4a0e4b0d e92d447b 589c41f0 26004680 09-14 10:26:51.803 13009 13009 I DEBUG : afd19228 686768a5 f9b5e006 b113300c 47c04628 09-14 10:26:51.803 13009 13009 I DEBUG : afd19238 35544306 37fff117 6824d5f5 d1ef2c00 09-14 10:26:51.811 13009 13009 I DEBUG : afd19248 e8bd4630 bf0081f0 00028344 ffffff88 09-14 10:26:51.811 13009 13009 I DEBUG : afd19258 b086b570 f602fb01 9004460c a804a901 09-14 10:26:51.811 13009 13009 I DEBUG : 09-14 10:26:51.811 13009 13009 I DEBUG : stack: 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1db8 00000000 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1dbc 00000000 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1dc0 00000000 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1dc4 00000000 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1dc8 afd4276c 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1dcc afd42718 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1dd0 00000000 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1dd4 afd19239 /system/lib/libc.so 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1dd8 00000001 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1ddc 45ac1e0c 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1de0 81b15340 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1de4 0000a000 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1de8 818d4ed1 /data/data/com.karmicapps/lib/libpromowall.so 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1dec afd1855b /system/lib/libc.so 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1df0 df002777 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1df4 e3a070ad 09-14 10:26:51.811 13009 13009 I DEBUG : #00 45ac1df8 0000001b 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1dfc 0000000e 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1e00 45ac1eac 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1e04 002ddb2c 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1e08 81b15340 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1e0c fffffbdf 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1e10 818d4ed1 /data/data/com.karmicapps/lib/libpromowall.so 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1e14 afd464b0 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1e18 002ddb2c 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1e1c afd13679 /system/lib/libc.so 09-14 10:26:51.811 13009 13009 I DEBUG : #01 45ac1e20 45ac1eac 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1e24 002ddb2c 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1e28 0000000e 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1e2c 00000000 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1e30 818d4ed1 /data/data/com.karmicapps/lib/libpromowall.so 09-14 10:26:51.811 13009 13009 I DEBUG : 45ac1e34 afd1453d /system/lib/libc.so

Please can anybody explain me causes of this?

But if I initialize string in such way:

ProtoMessage message; message.set_app_id(1111); message.set_hardware_id("test string"); std::string str; str = "test"; message.SerializeToString(&str);

everything is fine and proto serializes normally

std::string str;
message.SerializeToString(&str);

modify to :

std::string str;
message.SerializeToString(str);

delete &

fine ?

method SerializeToString() needs a pointer to a string
Your example isn’t compile

De Meng wrote:

std::string str;
message.SerializeToString(&str);
>
modify to :
>
std::string str;
message.SerializeToString(str);
>
delete &
>
fine ?

string str = signUpRequest.SerializeAsString()

That’s work fine, BUT if I try parse in such way:

@
RegistrationMessage message;
message.ParseFromString(str);
@
crash
but if I initialize string field:

@
RegistrationMessage message;
message.set_app_id(“0”); //string field
message.ParseFromString(str);
@
everything is OK.

I have much more troubles with parsing than with serialization

My protobuf serializes and parsing is fine in Android and ios.

can you tell me, please, how did you compile shared library? What version of protobuf, ndk?

protobuf 2.4.1
ndk r8b

compile args
LOCAL_ARM_MODE := arm
LOCAL_CPPFLAGS += -frtti

I uses script from this post:

tried to compile with ndk r8b and ndk r7 crystax.

I solved this problem one hour ago. All trick was in gnustl library. I link that lib like static library. But then I have read in ndk manual: ‘Please keep in mind that the static library variant of a given C++ runtime SHALL ONLY BE LINKED INTO A SINGLE BINARY for optimal conditions.’

Good luck!

i worked with it for two days ,nothing get、、、
Georgiy Lehovskiy ,have you get it?
how?
i cant use it in android。。。~~

wang fengli wrote:

i worked with it for two days ,nothing get、、、
Georgiy Lehovskiy ,have you get it?
how?
i cant use it in android。。。~~

If you have the same problem all that you need is to link gnustl as dynamic lib.
In Application.mk change APP_STL := gnustl_static to APP_STL := gnustl_shared