I have managed to build a static CPython library on Windows 10 by starting with the project here as a base (built around Visual C++ 2008):
https://github.com/zeha/python-superstatic
First, by using the prescribed instructions, I was able to get the library built in VS2015 by finding the workarounds listed beneath.
Once the library was built, I set about compiling and linking the supplied example c source, but soon reduced this to the following test code:
#include <stdio.h>
#include <Python.h>
int main()
{
Py_Initialize();
return 0;
}
I had to remove the bit in pyconfig.h which does this:
pragma comment(lib,"python27.lib")
so that it would look for the symbols in my static lib.
This does not compile, because the linker complains:
Source.obj : error LNK2001: unresolved external symbol __imp__Py_Initialize
I have added the path to the generated static library, pythonembed.lib, in:
Properties->Linker->General->Additional Library Directories
This is set to :
/workspace/superstatic-python/Python-2.7.3/PCbuild
I have also specified the library in (tried both bare lib name and absolute path):
Properties->Linker->Input->Additional Dependencies
This is set to:
pythonembed.lib
Running the command:
dumpbin.exe /all pythonembed.lib
shows that there is a symbol named _Py_Initialize. I have verified that both the static library and test project are built using the v140 toolset as a release build for 32 bit.
Have I missed any steps getting VC++ to link correctly?
The interesting bit is that the code calls Py_Initialise, the linker is looking for __imp__Py_Initialize, but the static library has the symbol: _Py_Initialize.
Does this point to the solution?
ISSUES to resolve to build the static library on Windows 10 with VS2015:
GNU Patch
GNU patch didn't work for me. It triggers UAC and loads in a new console, and does nothing. Seems to be triggering this behaviour because it's named 'patch.exe'. I found various work-arounds mentioned for this, but instead I used Cygwin's patch and put the Cygwin bin folder in the path.
Neither versions of 7zip downloaded came with a 7za.exe, so it was necessary to rename 7z.exe to 7za.exe
Nasm
nasm didn't install in the path supposed by instructions. Instead I used :
SET PATH=C:\Program Files\7-Zip;C:\Users\james\AppData\Local\nasm;%PATH%
Build environment
Instead of calling the VC++ 2008 SetEnv command to create the command line build environment, I used 'Developer Command Prompt for VS2015'.
PS: I started by getting this built in a VC++ 2008 environment, where all the above applied, but in addition, I had to solve the issue below. Once I had resolved this, I had the same linking issues as with the VS2015 build.
There is an issue installing the 7.1 SDK on Windows 10 due to a non-recognised .NET version in the registry. See:
Cannot install Windows SDK 7.1 on Windows 10
To install the 7.1 SDK with the full MSBuild tools, it was necessary to alter all locations in the registry (8, not the 2 reported, need to search) where the version of the installed .NET software is recorded: