Compiling Python to a static lib and using pythoncore.lib

Ida*_*dan 9 python static compilation static-libraries python-2.7

I'm trying to build Python 2.7 as a static single .lib file.

I've already made the following changes to the Python source code:

  1. Change to "Release" mode.
  2. Change all DLL projects to Static library (.lib) and set runtime library to /MT
  3. Add preprocessor definition Py_NO_ENABLE_SHARED to python and pythoncore

I've managed to compile the pythoncore project to pythoncore.lib (about 11mb size), but when trying to compile the python project I get the following linking errors:

error LNK2019: unresolved external symbol __Py_ActivateActCtx referenced in function __PyImport_GetDynLoadFunc C:\Python-2.7.3_Source\PCbuild\pythoncore.lib(dynload_win.obj) error LNK2019: unresolved external symbol __Py_DeactivateActCtx referenced in function __PyImport_GetDynLoadFunc C:\Python-2.7.3_Source\PCbuild\pythoncore.lib(dynload_win.obj) error LNK2019: unresolved external symbol __Py_hgidentifier referenced in function __PySys_Init C:\Python-2.7.3_Source\PCbuild\pythoncore.lib(sysmodule.obj) error LNK2019: unresolved external symbol __Py_hgversion referenced in function __PySys_Init C:\Python-2.7.3_Source\PCbuild\pythoncore.lib(sysmodule.obj) error LNK2019: unresolved external symbol _Py_GetBuildInfo referenced in function _Py_GetVersion C:\Python-2.7.3_Source\PCbuild\pythoncore.lib(getversion.obj)

谁能帮我?

谢谢,

伊詹

--------------------更新----------------------------- --------

我只是设法让它工作..如果它会帮助任何人,这些是我做的改变:

  1. 添加Modules\getbuildinfo.c到pythoncore项目.
  2. PC\dl_nt.c移动该线#ifdef Py_ENABLE_SHARED从线14至线79(正上方的DllMain).

......就是这样!

您现在可以链接到pythoncore.lib :)

伊詹