Search code examples
c++exceptiondllbotan

Unhandled exception in botan.dll


I am trying to run the most basic program with botan crypto library. I am using Botan 1.10 32bit. I got the binaries with their installer on Windows 7. IDE is Visual studio 2012.

I linked my project to botan.lib but the program reports a missing botan.dll on startup so I assume that the lib just links to the dll. Therefore I've put the botan.dll in the Debug folder.

Now to the problem.

#include <iostream>

#include <botan/botan.h>
using namespace Botan;
using namespace std;

int main(int argc, char* argv[]) {
    try {
        cout << "d1";
        LibraryInitializer init;  //exception thrown here
    }
    catch(exception& e) {
        cout << "Exception caught: " << e.what() << std::endl;
    }
    cout << "d2";
    return 0;
}

Intellisense detects everything ok. When I try to debug, I get:

First-chance exception at 0x6A1F2AA0 (botan.dll) in rsa.exe: 0xC0000005: Access violation reading location 0x00310000. Unhandled exception at 0x6A1F2AA0 (botan.dll) in rsa.exe: 0xC0000005: Access violation reading location 0x00310000.

It seems that an exception is thrown inside botan.dll and I can't catch it on my side. I cannot go further from here.

Did I do something wrong linking to the library or is there some other problem? Help appreciated.


Solution

  • To expand on my comment:

    If your program crashes even with a release build of your program, you'll have to download the source and build it yourself (python is required to configure the build).

    In case the release build does not crash, you can disable the /RTCs Stack Frames runtime check in your C++/Code Generation project settings for your debug build, which appears to be causing the crash. Simply change the setting from Both to /RTCu Uninitialized Variables or disable it altogether by setting it to Default.

    Since this is a workaround and not a solution, you should consider building botan yourself and build both release and debug versions (then you can link to the debug version in your debug build and leave the debug runtime checks as they are.

    Refer to the documentation on how to build it (you'll need python to run the configuration):

    Once you built the release version (default), copy the following files to another directory (for example C:\Botan\release\) or they will be overwritten when you build the debug version:

    • botan.dll
    • botan.exp
    • botan.lib
    • botan.dll.manifest

    Now run configure again, this time add the --enable-debug option:

    > python configure.py --cc=msvc --enable-debug
    

    and build it again. This time, copy the files (listed above) to C:\Botan\debug\.

    Configure your project to link to the library in the debug directory for debug builds and the one in the release directory for release builds. Finally make sure that your program loads the appropriate DLL when you run it.