Using a def file isn't the best way of doing this - you should save yourself the pain by using dllexport.
If you must use def files because it has been dictated, change your def file to
LIBRARY mylib
EXPORTS
?get_static_int@AAA@@SAAAHXZ
As you have discovered, the function is inlined so you need to uninline it. You could use /Ob0 on the cl line but I've never found that to work. It still gets inlined and you will still get the exception. mylib.hpp should be
class AAA
{
public:
static int & get_static_int();
private:
static int static_int_;
};
Add the following to mylib.cpp
int& AAA::get_static_int()
{
return static_int_;
}
If you do it this way, then it should run without throwing the exception.