Question

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.

Was it helpful?

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.

OTHER TIPS

The binaries you are using are probably aimed for release mode. I tried linking in debug mode and got access violation too, then I switched to release mode and everything worked fine. I'm also not sure if the binaries are aiming VC110. You could download the source and try to build it with your preferable configurations.

Since this is Windows you will not ever see a C++ exception cross a module boundary. Consequently your attempt to catch a C++ exception will fail to recognize this one. If you want to get your hands on an access violation you will need to use Structured Exception Handling instead.

To find out why the .dll is crashing you should set up Visual Studio to break into the debugger when an access violation is generated. Go to Debug -> Exceptions and tick the Thrown checkbox for c0000005 Access violation under Win32 Exceptions. Once in the debugger you can load the debugging symbols (assuming they are available). The call stack and parameters should give you a fairly good idea of why it is failing.

Since the source seems to be available you could also compile a Debug .dll yourself. This would both produce proper debugging symbols as well as enable source level debugging of the crash. This is likely to give you all the information you need to diagnose the issue at hand.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top