From my understanding reading this thread from several years ago, somebody once got Protocol Buffers working with Codegear C++ Builder 2007
https://groups.google.com/forum/?fromgroups=#!topic/protobuf/YapO_DqFVvc
The author of the above Builder 2007 version of protobuf uploaded it to a 3rd party URL, however the link to it seems to be long dead, and judging by the discussion and the current state of Protocol Buffers 2.5.0 the fix/change has never been forked from protobuf or merged into the trunk.
Updated:
When using generated code from protoc.exe (2.5.0) for either of the example .proto files, C++ Builder 2007 complains about a multitude of problems, including "duplicate entries" for names in the google::internal namespace (such as google::internal::kEmptyString
- it also complains about the std::hash
based containers and that memset
is an unrecognised symbol.
It took me several days to arrive at a solution, but here's how I managed to get it working in Codegear 2007:
Obtain the C++ Builder version of protobuf https://github.com/saadware/protobuf-cppbuilder - this is based on 2.4.1, so it is a little outdated, but I would guess that it's possible to merge the C++ builder changes into 2.5.0 (or whatever the latest version is). The C++ Builder version of protobuf is for Builder 2009, but it fixes various problems with std::hash
, so it's a better starting point than Google's release.
Take a copy of the following .cc
files in the ./src/google/protobuf
folder and change them to a .cpp
extension. There seems to be an issue with the .cbproj
format which doesn't like .cc
(You will need to add all of these files into your Codegear 2007 .cbproj - these are the files required for libprotobuf-lite).
extension_set.cpp
generated_message_util.cpp
message_lite.cpp
repeated_field.cpp
wire_format_lite.cpp
stubs\common.cpp
stubs\once.cpp
io\coded_stream.cpp
io\zero_copy_stream.cpp
io\zero_copy_stream_impl_lite.cpp
As per the thread by 'Dazza' use find-and-replace-in-files (e.g. Notepad++) to rename the google::internal namespace. Note that a case-sensitive find/replace is required because there are occurrences where the name 'Internal' is used for other things. For this step I followed Dazza's suggestion of changing it to google::internals
. (Note - this is both for the libprotobuf-lite and for the strings used to make the generated code)
In the generated code strings, search for all occurrences of memset
and change them to std::memset
(This is primarily for the code generator lib; libprotoc
. If you don't do this, every time you re-generate your .proto bindings, C++ builder will be unable to identify memset
.
Build protoc.exe using Visual Studio (I couldn't get Protoc.exe to build in Builder, but that shouldn't matter anyway, the code generator only needs to be built once)
Modify the example .proto files use the lite runtime;
option optimise_for = LITE_RUNTIME
. Note - reflection capabilities are not available with this option switched on.
Run protoc.exe
on your .proto file with --cpp_out
. The output file will have a .cc
extension - you will need to rename this to .cpp
Add your generated files to your project and build.
(Note- there are still a few warnings outstanding - one complaining about a superfluous &
taking the address of a function, and a few others complaining about signed/unsigned comparisons - but at least it builds and seems to work)