Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Highlighted
New Developer
Posts: 10
Registered: ‎07-15-2014
My Device: Z10
My Carrier: Vodafone

Porting Protobuf

I am having a lot of problems porting google protocol buffers protobuf library.

 

I have been following http://poweredbypenguins.wordpress.com/2013/07/27/google-protocol-buffers-and-blackberry-10/ a mix of the "porting libraries" threads and some custom tricks to make it compile.

 

I am using a mac for the crosscompile (as it seems to be imposible to do in Windows) I have been able to compile and link but now I face a SIGSEV without even calling a protobuf function:

 

Process 426639599 (Prot_On) terminated SIGSEGV code=1 fltno=11 ip=7856bf7c(/base/lib/libcpp.so.4@_ZNKSt6locale9_GetfacetEj+0x27) mapaddr=0002bf7c. ref=00000010

I am sure that someone else must be using protobuf for it's application so a little love on how to compile it (or just a precompiled binary) would be great.

Retired
Posts: 35
Registered: ‎10-15-2013
My Device: BlackBerry Z30
My Carrier: O2 UK

Re: Porting Protobuf

I've had a quick go at compiling protobuf. I'm not familiar with the library so please excuse me if I'm missing something obvious. From this post: https://code.google.com/p/protobuf-c/wiki/Examples#Protobuf-C_For_Embedded_Developers_(and_other_cro... I understand that I need a working protoc on my host machine (in my case OSX). 

 

Here's the steps I went through: 

 

1. Download and extract protobuf 2.5.0 from: https://code.google.com/p/protobuf/downloads/detail?name=protobuf-2.5.0.tar.gz&can=2&q=

 

2. Initialize a git repo within the protobuf directory - this is so you can always easily revert to the initial state of the protobuf source without all the artifacts created during the configure, make dance. As a side note, I find this to be an extremely valuable step when trying to compile any libraries from source.

 

git init
git add --all
git commit -m "Initial state"

 Now you can revert using: 

 

git clean -fd

 

3. Compile and install protoc for my host environment

 

./configure
make -j8
make install

#Verify
protoc --version
libprotoc 2.5.0

 

3. Now the host protoc is installed, revert the build environment. Without doing this I got linking errors during the cross compile, I think because make was trying to use the host linker rather than the BlackBerry linker. 

 

git clean -fd

 

4. Set up the BlackBerry NDK environment:

 

 

source /Applications/Momentics.app/bbndk-env_10_2_0_1155.sh

 

5. Configure the build: 

 

./configure --host=arm-unknown-nto-qnx8.0.0eabi --disable-protoc --with-protoc=protoc --prefix=`pwd`/build/arm-qnx

 

6. Make and install

 

make -j8 && make install

 

This should produce a library and headers under buid/arm-qnx. I haven't had a chance to test the library so I've attached it to this post. If you want to post some source code to test it I'd be happy to give it a whirl. 

 

Hope that helps!

 

New Developer
Posts: 10
Registered: ‎07-15-2014
My Device: Z10
My Carrier: Vodafone

Re: Porting Protobuf

Hi doturner,

 

Thank you for your time, I was able to compile it using the same process as you did except I was using an Ubuntu machine and that I tried using static version of the lib (the .a file).

Unfortunately I face the same error with your library even as the app starts:

 

Process 1085784308 (Prot_On) terminated SIGSEGV code=1 fltno=11 ip=7842bf7c(/base/lib/libcpp.so.4@_ZNKSt6locale9_GetfacetEj+0x27) mapaddr=0002bf7c. ref=00000010

 I will try to generate a minimal project reproducing the issue so you can try to debug the issue.

New Developer
Posts: 10
Registered: ‎07-15-2014
My Device: Z10
My Carrier: Vodafone

Re: Porting Protobuf

I have created a minimal project using your library that reproduces the error

 

https://copy.com/SWOhwyidWnnw

Retired
Posts: 35
Registered: ‎10-15-2013
My Device: BlackBerry Z30
My Carrier: O2 UK

Re: Porting Protobuf

Thanks for posting that. I've got it set up, and recreated my own project from scratch and both apps crash on on startup. The message I receive is different though: 

 

Process 385605901 (ProtobufTest) terminated SIGSEGV code=1 fltno=11 ip=01277fc0(/usr/lib/ldqnx.so.2@__krait_neon_memset+0x80) mapaddr=00067fc0. ref=813bdde1

 

I have raised this with one of our experts internally for further investigation. I'm thinking it's some basic incompatibility with the BlackBerry C library.

 

What is the exact configure command you're using to compile the protobuf library? 

New Developer
Posts: 10
Registered: ‎07-15-2014
My Device: Z10
My Carrier: Vodafone

Re: Porting Protobuf

./configure --host=arm-unknown-nto-qnx6.5.0eabi --disable-proto-c --with-protoc=protoc --prefix=`pwd`/build/arm-qnx

 That was the simplest try, I have also tried a lot of other with parameters based on different posts:

 

http://supportforums.blackberry.com/t5/Native-Development/Porting-libraries-ZeroMQ/m-p/2698581/highl...

 

http://supportforums.blackberry.com/t5/Native-Development/Porting-Libraries-id3/m-p/2651731/highligh...

 

http://poweredbypenguins.wordpress.com/2013/07/27/google-protocol-buffers-and-blackberry-10/

 

Most of my tries ended with the library not compiliing and the ones that compiled failed in the same way as posted.

I hoped that the ZeroMQ build config could fix the issue as it seems that the same error was happening with that library but I was unable to make it build.

Retired
Posts: 35
Registered: ‎10-15-2013
My Device: BlackBerry Z30
My Carrier: O2 UK

Re: Porting Protobuf

Having spoken to one of my (far more experienced) colleagues it looks like the error is caused by mixing Dinkum and gcc stdc++ code. The two are not ABI compatible.

 

This means that the library needs to be recompiled against libcpp - the same way that ZeroMQ is compiled. I tried this and (same as you) ran into compile errors: 

 

Configure flags (almost identical to ZeroMQ): 

 

./configure \
    --host=arm-unknown-nto-qnx8.0.0eabi \
    --prefix=`pwd`/build/arm-qnx \
    CC="qcc -V4.6.3,gcc_ntoarmv7le -lang-c++" \
    CXX="qcc -V4.6.3,gcc_ntoarmv7le -lang-c++" \
    LDFLAGS=-Wl,--no-undefined \
    LIBS="-lcpp"

 

Compile error: 

 

In file included from ./google/protobuf/stubs/hash.h:43:0,
                 from google/protobuf/extension_set.cc:35:
/Applications/Momentics.app/target_10_2_0_1155/qnx6/usr/include/cpp/hash_map: In instantiation of 'std::_Hmap_traits<std::pair<const google::protobuf::MessageLite*, int>, google::protobuf::internal::ExtensionInfo, google::protobuf::hash<std::pair<const google::protobuf::MessageLite*, int> >, std::equal_to<std::pair<const google::protobuf::MessageLite*, int> >, false>':
/Applications/Momentics.app/target_10_2_0_1155/qnx6/usr/include/cpp/xhash:180:8:   instantiated from 'std::_Hash<std::_Hmap_traits<std::pair<const google::protobuf::MessageLite*, int>, google::protobuf::internal::ExtensionInfo, google::protobuf::hash<std::pair<const google::protobuf::MessageLite*, int> >, std::equal_to<std::pair<const google::protobuf::MessageLite*, int> >, false> >'
/Applications/Momentics.app/target_10_2_0_1155/qnx6/usr/include/cpp/hash_map:79:8:   instantiated from 'std::hash_map<std::pair<const google::protobuf::MessageLite*, int>, google::protobuf::internal::ExtensionInfo, google::protobuf::hash<std::pair<const google::protobuf::MessageLite*, int> >, std::equal_to<std::pair<const google::protobuf::MessageLite*, int> > >'
./google/protobuf/stubs/hash.h:172:7:   instantiated from 'google::protobuf::hash_map<std::pair<const google::protobuf::MessageLite*, int>, google::protobuf::internal::ExtensionInfo>'
google/protobuf/extension_set.cc:68:10:   instantiated from here
/Applications/Momentics.app/target_10_2_0_1155/qnx6/usr/include/cpp/hash_map:24:3: error: no class template named 'rebind' in 'struct std::equal_to<std::pair<const google::protobuf::MessageLite*, int> >'

Searching I found someone having a similar problem cross compiling: https://groups.google.com/forum/#!msg/protobuf/7knJAh5Ay28/GAc2pUJS8CoJ

 

It may be that we'll need to use the boost library to get this working. 

 

New Developer
Posts: 10
Registered: ‎07-15-2014
My Device: Z10
My Carrier: Vodafone

Re: Porting Protobuf

Umm I will try to follow that path tomorrow, I also thought about statically linking stdc++ to protobuf, I was unable to do it but thought that maybe it could also fix the issue.

New Developer
Posts: 10
Registered: ‎07-15-2014
My Device: Z10
My Carrier: Vodafone

Re: Porting Protobuf

[ Edited ]

It seems I finally got it working, I needed to use Boost BB10 (https://github.com/blackberry/Boost) and the final configure line was a bit more complex:

./configure --host=arm-unknown-nto-qnx8.0.0eabi --disable-proto-c --with-protoc=protoc --prefix=`pwd`/build/arm-qnx CC="qcc -V4.4.2,gcc_ntoarmv7le -lang-c++" CXX="qcc -V4.4.2,gcc_ntoarmv7le -lang-c++" LDFLAGS=-Wl,--no-undefined LIBS="-lcpp -lm -lgcc" CPPFLAGS="-I/PATH_TO_BOOST/stage/include"

 As a side effect I does not need any other library so it works with

LIBS += -lprotobuf

 In case anyone else needs them here are the headers and the shared library: https://copy.com/VAeknvjuFPnr

 

Of course, thank you very much for your effort and hints doturner

Retired
Posts: 35
Registered: ‎10-15-2013
My Device: BlackBerry Z30
My Carrier: O2 UK

Re: Porting Protobuf

[ Edited ]

That is great news. Did you have to build boost? If so, what commands did you use? 

 

Also, did you have to make any changes to the protobuf source?