Incidentally, my understanding is that the C++ standard says that dynamic
initializers only need to be run before the first time the module is
accessed (not necessarily before main()).  Thus, if your program contains no
symbols referring to the module, then it will never be accessed, and dynamic
initializers are not required to be run at all.  Therefore GCC's behavior is
arguably correct.  A work-around is to add dummy calls to your main()
function to each module that you want to force to be linked in.

On Tue, Aug 17, 2010 at 12:32 PM, Doug Coburn <dougco...@gmail.com> wrote:

> OK, I think I found the solution.
>
> On Aug 16, 11:40 am, Doug Coburn <dougco...@gmail.com> wrote:
> >
> > #########################################
> > # Build instructions
> > ########################################
> >
> > > mkdir generated
> > > protoc --cpp_out=./generated *.proto
> > > g++ -c generated/base.pb.cc -o generated/base.pb.cc.o
> > > g++ -c generated/extension.pb.cc -o generated/extension.pb.cc.o
> > > g++ -c generated/glue.pb.cc -o generated/glue.pb.cc.o
> > > ar cr protocollection.a generated/*.cc.o
> > > g++ main.cpp protocollection.a -o app -lprotobuf -lpthread
>
> This should be :
>      g++ main.cpp -Wl,-whole-archive protocollection.a -Wl,-no-whole-
> archive -o app -lprotobuf -lpthread
>
> Which will force the linker to include all of the object files in the
> archive rather than just the ones it thinks it needs.
>
> >
> > #########################################
> > # Results
> > ########################################
> >
> > > ./app
> >
> > Initializing extension type: extension
>
> It appears that there is nothing you can do in the protobuf sources to
> fix this as the linker is not even including the compiled object
> files.  This is a g++ issue.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To post to this group, send email to proto...@googlegroups.com.
> To unsubscribe from this group, send email to
> protobuf+unsubscr...@googlegroups.com<protobuf%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/protobuf?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to proto...@googlegroups.com.
To unsubscribe from this group, send email to 
protobuf+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/protobuf?hl=en.

Reply via email to