[Botan-devel] Re: Problem with Botan LibraryInitializer

Carlton Davis carlton at cs.mcgill.ca
Thu Dec 15 13:18:26 EST 2005


Thanks for your prompt response.
Here is the situation, in one header file where a certain
packet header is specified as a struct, I need to include
a field for storing a signature; so the relevant code in
to header file looks like this:
struct SRPacket{
  Packet *pkt;                  /* the inner NS packet */
  Path route;
  SecureVector<byte> signature;

Then in another header file other packet header types are also
specified as struct, and again I need to add a field to store
signatures. The relevant code for this header file looks like
struct route_request {
  int   req_valid_;     /* request header is valid? */
  int   req_ttl_;       /* max propagation */
  SecureVector<byte> signatures[MAX_SR_LEN];

If I don't add the line "LibraryInitializer init;"
in these header files, the program compiles. However, when I
try running it it crashes and output the following message:
"terminate called after throwing an instance of 'Botan::Invalid_State'
  what():  Botan: LibraryInitializer not created, or it failed"

I thought of fixing this by initialing the botan library in
the relevant header files but this doesn't work in that I get
the compile error message: "multiple definition of init".

The code for the simulation startup is in one of the many .cc
files; so, initializing the botan library there won't have any
bearing on the header files where the various packet headers are

Any other ideas on what I could possible do?

Thanks and best regards,


Hi Carlton,

I've got to say, the idea of declaring LibraryInitializer itself as a
makes me feel a little queasy... but hey, if it works, it works.

There really isn't any way to do what you're looking for directly in
C/C++... is there any way to instead declare init in a source file? If you
declare it as a global in a file, C++ guarantees that the constructor will
sometime before main() starts (though you still won't be able to construct
global Botan objects safely, because C++ does not specify the order in
global objects are created).

Is there any way to hook into simulation startup and shutdown? Using
Init::initializer and Init::deinitialize may be easier to use than the
LibraryInitializer object.


On Thu, Dec 15, 2005 at 12:21:13PM -0500, Carlton Davis wrote:
> Hello,
> I am using Botan in a routing protocol I plugged into a network
> simulator. When I try to compile the program, I get this error
> message: "multiple definitions of init". This is due to the line:
> "LibraryInitializer init;" appearing more than once in the included
> header file. I know that Jack mentioned in the Botan tutorial that
> the use of global botan variables is a bad idea, but I can't think
> of a way to avoid using the botan variables in the relevant header
> files because of the way the simulator code is written. My
> question is, is there a way to test if the Botan
> library has been initialized in an included header file,
> before doing the initialization (ie is it possible to do something
> of the sort
>    LibraryInitializer init;
> #endif
> Thanks and best regards,
> -Carlton

More information about the botan-devel mailing list