Access violation when embedding Python on Windows
I need help understanding why embedded Python is crashing in this extremely simple test case on Windows.
This works great:
#ifdef _DEBUG
#undef _DEBUG
#include <Python.h>
#define _DEBUG
#endif
#include <iostream>
int main()
{
Py_Initialize();
std::cout << "Hello world!" << std::endl;
PyRun_SimpleString("print(\"Hello world!\")");
return 0;
}
This crashes with an access violation:
#ifdef _DEBUG
#undef _DEBUG
#include <Python.h>
#define _DEBUG
#endif
#include <iostream>
int main()
{
Py_Initialize();
std::cout << "Hello world!" << std::endl;
std::cout << Py_GetPythonHome() << std::endl;
return 0;
}
My research has led me here. I determined that my python installation (2.6.5) is compiled to use msvcr90.dll
and the embedding program uses msvcr100.dll
.
The first thing that grabbed my attention was that Py_GetPythonHome()
surely checks environment variables, one of the flagged problems of having multiple MS C runtimes used in a single application. However according to the MSDN example, I should only expect the environment variable values to be out of synch, not to c开发者_如何学运维ause an access violation.
Please help me understand!
精彩评论