[Botan-devel] App crashes trying to load certificate (VC7, Windows XP)

Ritwick Dhar ritwick.dhar at gmail.com
Wed Jun 8 17:51:29 EDT 2005


Thanks for the quick reply - got rerouted into other things, hence the delay.
Yes, the test applications all build and run fine.
And you're right, the linking problem was the due to different C
libraries. I created a VC project for Botan, and added my existing
project to the solution, making it dependent on the Botan project.
Now it builds fine, but still crashes with this error at runtime:
-----------------
Object reference not set to an instance of an object.
   at Botan.MemoryRegion<unsigned
char>.deallocate(MemoryRegion<unsigned char>* , Byte* p, UInt32 n) in
d:\documents\wor
karea\botan\botan-1.4.6-src\build\include\botan\secmem.h:line 88
   at Botan.MemoryRegion<unsigned char>.__dtor(MemoryRegion<unsigned
char>* ) in d:\documents\workarea\botan\botan-1.4.6
-src\build\include\botan\secmem.h:line 72
   at __CxxCallUnwindDtor(IntPtr , Void* )
   at Botan.SecureVector<unsigned char>.__ctor(SecureVector<unsigned
char>* , UInt32 n) in d:\documents\workarea\botan\b
otan-1.4.6-src\build\include\botan\secmem.h:line 190
   at Botan.X509.load_key(basic_string<char,std::char_traits<char>,std::allocator<char>
>* )
   at main() in d:\documents\workarea\pki_botan\pki_botan.cpp:line 20
-----------------
The line in secmem.h is 
----------------
      void deallocate(T* p, u32bit n) const
         { alloc->deallocate(p, sizeof(T)*n); }
---------------

I also saw the new post about VC users. One user seems to have the
exact same configuration as mine, and is having no trouble. I'll ask
him what his project settings are.

Regards
Rit

On 6/6/05, Jack Lloyd <lloyd at randombit.net> wrote:
> 
> Well, first things first - does the test application build/run? Part of that
> code involves doing some (fairly minimal) testing of the X.509 code. I think it
> is likely that it will work just fine, VC7 seems to be quite capable compared
> to earlier versions, but just in case...
> 
> What it looks like is that the standard C library that Botan linked against and
> the standard C library that your application links against are different
> versions - Windows has (IIRC) four variants: multiple threads, single threaded,
> and debug versions of both of those. Everything has to link against the same
> one or things get very confused, and that looks like what is happening here.
> 
> Probably the 'right' thing to do is rebuild Botan, modifying the makefile to
> use the right flag so that Botan is built against the same version of the C
> library as your application is - I believe the flags in question are /MD, /ML,
> or /MT, but I don't know what the default is, or what your app is expecting, so
> I can't tell you which one you should actually be using in this case.
> 
> Hope this helps,
>   Jack
> 
> On Mon, Jun 06, 2005 at 11:07:22AM -0500, Ritwick Dhar wrote:
> > Hello,
> >
> > I'm a new Botan user - just trying to get a sample app to load a X509
> > cert. Botan built fine using the config file and nmake, creating
> > libbotan.lib. However, while trying to build my app, I get the
> > following linker error:
> >
> > --------------------------
> > libcpmt.lib(xlock.obj) : error LNK2005: "public: __thiscall
> > std::_Lockit::_Lockit(int)" (??0_Lockit at std@@QAE at H@Z) already defined
> > in libbotan.lib(pipe_io.obj)
> > libcpmt.lib(xlock.obj) : error LNK2005: "public: __thiscall
> > std::_Lockit::~_Lockit(void)" (??1_Lockit at std@@QAE at XZ) already defined
> > in libbotan.lib(pipe_io.obj)
> >
> > --------------------------
> > If I exclude the library libcpmtd.lib using the
> > /NODEFAULTLIB:"libcpmtd.lib" option, I get a bunch of errors saying:
> > ---------------------
> > LIBC.lib(crt0dat.obj) : error LNK2005: ___crtExitProcess already
> > defined in LIBCMT.lib(crt0dat.obj)
> > LIBC.lib(crt0dat.obj) : error LNK2005: __cinit already defined in
> > LIBCMT.lib(crt0dat.obj)
> > LIBC.lib(crt0dat.obj) : error LNK2005: _exit already defined in
> > LIBCMT.lib(crt0dat.obj)
> > LIBC.lib(crt0dat.obj) : error LNK2005: __exit already defined in
> > LIBCMT.lib(crt0dat.obj)
> > LIBC.lib(crt0dat.obj) : error LNK2005: __cexit already defined in
> > LIBCMT.lib(crt0dat.obj)
> > ....
> > -------------------
> >
> > If I exclude both offending libraries with /NODEFAULTLIB:"libcpmt.lib"
> >  and /NODEFAULTLIB:"libcmt.lib", the application builds, but crashes
> > at runtime with an exception:
> > ---------------------
> > Object reference not set to an instance of an object.
> >    at Botan.MemoryRegion<unsigned char>.__dtor(MemoryRegion<unsigned char>* )
> >    at Botan.X509.load_key(basic_string<char,std::char_traits<char>,std::allocator<char>
> > >* )
> >    at main()
> > --------------------
> > The offending line is:
> >               X509_PublicKey* key = X509::load_key("d:\\documents\\workarea\\pubCert.pem");
> >
> >
> > Any help is greatly appreciated.
> >
> > Regards
> > Rit
> > _______________________________________________
> > botan-devel mailing list
> > botan-devel at randombit.net
> > http://www.randombit.net/mailman/listinfo/botan-devel
>



More information about the botan-devel mailing list