C++ Builder + Protobuff

683 views
Skip to first unread message

Stamatis Liatsos

unread,
Sep 21, 2011, 9:04:28 PM9/21/11
to Protocol Buffers
Hello,
I am having some problems when i am trying to compile the protobuf lib
with the c++ builder compiler.
It looks like that a lot of things need to be changed for the sources
to get compiled.
I have read over the internet about a guy (Dazza) that compiled the
lite 2.3.0 version with some modification.
Unfortunately i can't find the patch so i would like to ask, is there
anyone here that has the patch file?
Thanks a lot in advance and sorry for my english.

Scott Saad

unread,
Sep 22, 2011, 5:17:29 PM9/22/11
to prot...@googlegroups.com
Hi there. I don't have the patch you're referring to but I'm looking at getting this compiling. So far I've not had a lot of success as I'm getting hung up on the hash.h file. For some reason C++Builder is blowing up everywhere with this one. I'm still trying to track things down. 

I can keep you posted on any success I may find. The hope would be that if I get this building, and tests running, I can make it available. 

Thanks,
Scott

Stamatis Liatsos

unread,
Sep 22, 2011, 6:17:21 PM9/22/11
to Protocol Buffers
The hash.h contains some functions in case ur compiler doesn't have a
library with hashing functions if i am not mistaken (aka hash_map
etc).
C++ Builder does have those functions in its lib (xhash.h) and so
those functions collide with the ones bcb provides, u will need to
modify the _MSV_VER(or h/e it is called) to __BUILDERC__ and do some
more modifications. I managed to get past of some of the error
messages but more poped up. I was in need of the library because i
have a project in the uni but i gave up...I will help with the
conversion as soon as i have some spare free time.

Scott Saad

unread,
Sep 22, 2011, 7:56:18 PM9/22/11
to prot...@googlegroups.com
Good to hear somebody else is trying to do or has tried to do this. I have defined hash/hash_map/hash_set in the section for the __BUILDERC__ (I named it _CPPBUILDER but same thing). 

Anyway I'm getting all sorts of E2238 errors (multiple declarations for hash<Key> and hash_map, etc). I'm trying to make sense of these errors in the context of protobuf. There errors first come when compiling descriptor.cc, where the first thing it does is include hash.

In hopes of isolating the compile problem(s) I've taken the exact same hash related declarations and created a separate project (outside of protobuf). It builds fine in this case.

Might be a namespace issue. Not sure yet. 

Stamatis Liatsos

unread,
Sep 23, 2011, 11:10:56 AM9/23/11
to Protocol Buffers
You can try to rename all the hash declarations to something like
hashh_key. This worked for me, it is a bit dirty tho :s

Stamatis Liatsos

unread,
Sep 23, 2011, 11:20:31 AM9/23/11
to Protocol Buffers
Btw i am not sure about that since i have barely used those tools.
But i was thinking that it would be possible to compile the libs using
MSVC++
and then we could use the coff2omf tool that the bcb ide provides for
the libs generated with the
ms compiler. I am gonna give it a shot but i have read that it needs a
lot of modifications for the lib to be usable
using this proccess.

Stamatis Liatsos

unread,
Sep 23, 2011, 11:29:47 AM9/23/11
to Protocol Buffers
Sorry for the multiple posts, if u are intrested in trying this way
first
you can check this out
http://bcbjournal.org/articles/vol4/0012/Using_Visual_C_DLLs_with_CBuilder.htm?PHPSESSID=82d2fe4dbaac6c5a956c8908bb64ea87
I am gonna give it a shot when i have the time.

Scott Saad

unread,
Sep 23, 2011, 12:01:56 PM9/23/11
to prot...@googlegroups.com
The concept sounds good but in this case I'm not sure how it's going to work. For one, I would imagine you still need to build the generated protobuf files, which in turn include various header files from the project. 

For example, if you have a buffer with a format of the following:

package MyNameSpace;
message Customer {
required string Number = 1;
optional string Name = 2;
}

You'll get Customer.pb.h and Customer.pb.cc files generated after running the protobuf compiler. These two files you'll need to make part of your C++Builder project in order to properly serialize/deserialize the messages. These two files have various includes to the protobuf source, which in turn leads us back to needing to get it compiling in C++Builder.

Maybe I'm not thinking of something here and you have other ideas. Let me know your thoughts.

Scott

Stamatis Liatsos

unread,
Sep 23, 2011, 12:34:50 PM9/23/11
to Protocol Buffers
Yeah you are right, i just forgot about the generated files.

•Jonas•

unread,
Sep 25, 2011, 6:26:56 AM9/25/11
to Protocol Buffers
May Im just being stupid, but this is seems only for C functions --
and wont the compiler (PROTO) generated class require calling c++
code in this DLL and hence huge problem with name-mangling will coem ?

Scot: I really, really hope you can get it to compile natively. Would
be so great.


On 23 Sep., 17:29, Stamatis Liatsos <patria...@windowslive.com> wrote:
> Sorry for the multiple posts, if u are intrested in trying this way
> first
> you can check this outhttp://bcbjournal.org/articles/vol4/0012/Using_Visual_C_DLLs_with_CBu...

Stamatis Liatsos

unread,
Sep 27, 2011, 9:52:32 AM9/27/11
to Protocol Buffers
Yeah Jonas and that's why i said that i forgot about the generated
file.

Btw Scott in case you have started you should check this out too
(config.h inside the ms project folder):
http://protobuf.googlecode.com/svn/trunk/vsprojects/config.h

I am sure that bcb 2007 and later have hash_map.h and hash_set.h in
their libs so the lines beyond have to be changed:
#if _MSC_VER < 1310 || _MSC_VER >= 1600
#define HASH_NAMESPACE std
#else
#define HASH_NAMESPACE stdext
#endif

into something like this:
#if _MSC_VER < 1310 || _MSC_VER >= 1600 || defined(__BORLANDC__) //I
am not aware of the versioning numbers so i am checking only if it is
defined.
#define HASH_NAMESPACE std
#else
#define HASH_NAMESPACE stdext
#endif

I am not sure if this file needs further modifications but this would
suffice.
Note that on my 2nd post i said __BUILDERC__ but there correct one was
__BORLANDC__

Scott Saad

unread,
Sep 28, 2011, 3:22:42 PM9/28/11
to prot...@googlegroups.com
I actually have most of it compiling
  • libprotobuf 
  • gtest
  • gtest_main
  • libprotobuf-lite
I'm currently trying to get libprotc compiling and failing somewhere around what seems to be Google's implemtation around scoped_ptr for the ExtensionGenerator, ServiceGenerator, EnumGenerator and MessageGenerator. Still trying to make sense of the compile errors.

So here is what is left to do
  • libprotoc
  • lite-test
  • protoc
  • test_plugin
  • tests
Obviously these still need to be made to compile, but I'm optimistic they won't be too difficult. After compiling, I'm going to get all tests running as well.

A positive thing here is that I've been ensuring that my changes continue to compile in MSVC and that tests still run under the generated binaries. I hope to also test my changes on gcc. 

Anyway, I'll keep you posted on progress.

Scott

Stamatis Liatsos

unread,
Sep 29, 2011, 7:39:52 PM9/29/11
to Protocol Buffers
Pretty good job Scott, i am sorry that i can't contribute but i am in
the middle
of the semester's tests so i don't have free time. If you are still
stuck in about two weeks from now
that i will be done with the tests i am willing to help you.

•Jonas•

unread,
Oct 6, 2011, 11:10:43 AM10/6/11
to Protocol Buffers

How is things looking ?
Im really intersting in using libprotobuf-lite so I hope all your
hardwork pays off.
Thank you for trying.

Scott Saad

unread,
Oct 10, 2011, 12:45:20 PM10/10/11
to prot...@googlegroups.com
Hi Jonas,

I'm definitely making progress. I have everything compiling now but am running across some runtime errors (with reflection) when running the newly compiled protoc.exe. Therefore I'm making adjustments and trying again. 

Very simple messages are working fine, however I'm using the included examples and unit tests as a litmus test to make sure all is working. Needless to say, I have a bit to figure out. 

I have created a fork of the Protobuf project on github to help manage changes. You're welcome to have a look: https://github.com/saadware/protobuf-cppbuilder.

Most of the changes (if not all) are compile time (syntax changes) to make it compile across all three environments (gcc, MSVC and C++Builder).

Take care,
Scott


•Jonas•

unread,
Oct 23, 2011, 5:14:25 AM10/23/11
to Protocol Buffers
Hi Scott,
I am -very- impressed.
I did try to compile it myself, but gave up as so many wierd errors.

Having everything compile is quite an achievement!

If the bcb compiled version can handle all test examples, one must
assume
its as bug free as software gets :)

Downloading saadware-protobuf-cppbuilder right now.

On behalf of all bcb users. thank you for porting this cool tool to
this compiler.




Reply all
Reply to author
Forward
Message has been deleted
0 new messages