adding dllexport in generated headers?

1,668 views
Skip to first unread message

ojwl...@googlemail.com

unread,
Aug 26, 2008, 5:22:21 AM8/26/08
to Protocol Buffers
To generate a DLL which uses protocol-buffers as part of its
interface, the autogenerated *.pb.h would need to have some sort of
"__declspec( dllexport )" in each class declaration. Is it possible
to make protoc.exe generate these?

Kenton Varda

unread,
Aug 26, 2008, 4:56:37 PM8/26/08
to ojwl...@googlemail.com, Protocol Buffers
Yes.  There is an undocumented option to --cpp_out which will do this:

--cpp_out=dllexport_decl=MY_EXPORT_MACRO:output/direcotry

For an example of this, see generate_descriptor_proto.sh, which generates descriptor.pb.{h,cc} from descriptor.proto.

It's undocumented because I'm concerned that exposing protocol buffer objects from DLLs may not be a great idea in general due to ABI compatibility issues -- e.g. if you add a new field and recompile your DLL, every program linked against it will also have to be recompiled.  But, if you know what you're doing, feel free to use it.
Reply all
Reply to author
Forward
0 new messages