Protobuf with MSVC: how to export generated Message

3,281 views
Skip to first unread message

Carlo Medas

unread,
Sep 22, 2009, 4:14:40 AM9/22/09
to Protocol Buffers
Dears,

we have a rpc.proto built inside our core framework, built as a DLL.

Other protos contain extension to base message defined in rpc.proto,
and they are built in separate and different executables.

The MSVC linker compains for error since the RpcMessage class (defined
in rpc.proto) and related extension factory methods are not declared
with __declspec(dllexport) option when built in the DLL.

Is there an option in the protoc compiler to make it generate the
dllexport/dllimport options, exactly as you did for your Message base
class with macro LIBPROTOBUF_EXPORT?

Thanks in advance and keep up the amazing work,

Carlo Medas

Kenton Varda

unread,
Sep 22, 2009, 12:37:17 PM9/22/09
to Carlo Medas, Protocol Buffers
If you invoke protoc like:

  protoc --cpp_out=dllexport_decl=MY_EXPORT_MACRO:path/to/output/dir myproto.proto

then it will generate code with MY_EXPORT_MACRO in all the right places.  However, this option is incomplete -- currently there is no way to force the generated .pb.h to #include a header which defines MY_EXPORT_MACRO.  I'm open to patches to fix this.  Or, you could use a hack to work around it, such as adding the #include via some sort of text processing after protoc finishes, or perhaps moving the .pb.h to .pb2.h and replacing the .pb.h file with one that first includes your header then includes the .pb2.h...

Aron Bierbaum

unread,
Sep 22, 2009, 3:20:56 PM9/22/09
to Kenton Varda, Carlo Medas, Protocol Buffers
We currently get around this limitation by forcing the the header to
be included using compiler command line flags:

Windows: /FIproject/Config.h
Linux: -include project/Config.h

-Aron

Carlo Medas

unread,
Sep 25, 2009, 5:22:03 AM9/25/09
to Protocol Buffers
Dear Kenton and Aron,

thank you very much for your prompt answers.

With Kenton's suggestion, we were able to have our custom
OVERLOOK_EXPORT macro in the generated .pb files.

By using Aron's idea we then managed to force inclusion of our
exports.h file.

Thank you all again.
Kind regards,

Carlo

On 22 Set, 21:20, Aron Bierbaum <aronbierb...@gmail.com> wrote:
> We currently get around this limitation by forcing the the header to
> be included using compiler command line flags:
>
> Windows: /FIproject/Config.h
> Linux: -include project/Config.h
>
> -Aron
>
>
>
> On Tue, Sep 22, 2009 at 11:37 AM, Kenton Varda <ken...@google.com> wrote:
> > If you invoke protoc like:
> >   protoc --cpp_out=dllexport_decl=MY_EXPORT_MACRO:path/to/output/dir
> > myproto.proto
> > then it will generate code with MY_EXPORT_MACRO in all the right places.
> >  However, this option is incomplete -- currently there is no way to force
> > the generated .pb.h to #include a header which defines MY_EXPORT_MACRO.  I'm
> > open to patches to fix this.  Or, you could use a hack to work around it,
> > such as adding the #include via some sort of text processing after protoc
> > finishes, or perhaps moving the .pb.h to .pb2.h and replacing the .pb.h file
> > with one that first includes your header then includes the .pb2.h...
>
Reply all
Reply to author
Forward
0 new messages