环境配置
(1)python的lib 以及头文件分别加到vc的include/lib directories中去。
(2)写完编译后出现找不到python33_d.lib 错误,出现这个错误的原因是:python_d.lib是 库的调试后形式,当我们以debug模式编译工程时,python就用这个lib文件,但是这个文件是不可用 的。对于这点,最快的办法就是强制要求python在任何情况下都是用非调试版本,就可以了。
所以要做的是:
- 修改python头文件pyconfig.h的配置,修改指向调试库文件的参数,由
- # if defined(_DEBUG)
- # pragma comment(lib,"python33_d.lib")
- # elif defined(Py_LIMITED_API)
- # pragma comment(lib,"python3.lib")
- # else
- # pragma comment(lib,"python33.lib")
- # endif /* _DEBUG */
修改为:
- # if defined(_DEBUG)
- # pragma comment(lib,"python33.lib")
- # elif defined(Py_LIMITED_API)
- # pragma comment(lib,"python3.lib")
- # else
- # pragma comment(lib,"python33.lib")
- # endif /* _DEBUG */
(3)在Visual Studio中编译时必须注意,若Python为64bit而VS C++ Project Config里的platform是32bit,会报错:
- Error 1 error LNK2019: unresolved external symbol __imp__Py_Finalize referenced in function _main
- Error 2 error LNK2019: unresolved external symbol __imp__PyEval_CallObjectWithKeywords referenced in function _main
- Error 3 error LNK2019: unresolved external symbol __imp__PyObject_GetAttrString referenced in function _main
- Error 4 error LNK2019: unresolved external symbol __imp__PyImport_ImportModule referenced in function _main
- Error 5 error LNK2019: unresolved external symbol __imp__Py_Initialize referenced in function _main
- Error 6 error LNK1120: 5 unresolved externals
注意修改自己的platform