Как получить Python .pyd для Windows из исходного кода c / c ++? (обновление: оживленный теперь в Python на тот случай, если вы этого хотите)

How to get from C/C++ extension source code to a pyd file for windows (or other item that I could import to Python)?

edit: Специальная библиотека, которую я хотел использовать (BRISK), была включена вOpenCV 2.4.3, поэтому моя потребность в этом умении ушла на время. Если вы пришли сюда в поисках BRISK, вот простойBRISK в демонстрации Python что я отправил.

у меня естьюркий исходный код (скачать), что я хотел бы построить и использовать в моем приложении Python. Я дошел до генерации файла brisk.pyd ... но это было 0 байтов. Если есть лучший / альтернативный способ нацеливания на файл brisk.pyd, то, конечно, я открыт для этого.

edit: Пожалуйста, игнорируйте все попытки в моем первоначальном вопросе ниже и посмотрите мой ответ, который стал возможен благодаря подробному прохождению obmarg.

Where am I going wrong?

Distutils without library path: First I tried to build the source as is with distutils and the following setup.py (I have just started learning distutils so this is a shot in the dark). The structure of the BRISK source code is at the bottom of this question for reference.

from distutils.core import setup, Extension
module1 = Extension('brisk',
    include_dirs = ['include', 'C:/opencv2.4/build/include', 'C:/brisk/thirdparty/agast/include'],
    #libraries = ['agast_static', 'brisk_static'],
    #library_dirs = ['win32/lib'],
    sources = ['src/brisk.cpp'])
setup (name = 'BriskPackage',
    ext_modules = [module1])

That instantly gave me the following lines and a 0 byte brisk.pyd somewhere in the build folder. So close?

running build
running build_ext

Distutils with library path: Scratch that attempt. So I added the two library lines that are commented out in the above setup.py. That seemed to go ok until I got this linking error:

creating build\lib.win32-2.7
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:win32/lib /LIB
PATH:C:\Python27_32bit\libs /LIBPATH:C:\Python27_32bit\PCbuild agast_static.lib brisk_static.lib /EXPORT:initbrisk build
\temp.win32-2.7\Release\src/brisk.obj /OUT:build\lib.win32-2.7\brisk.pyd /IMPLIB:build\temp.win32-2.7\Release\src\brisk.
lib /MANIFESTFILE:build\temp.win32-2.7\Release\src\brisk.pyd.manifest
LINK : error LNK2001: unresolved external symbol initbrisk
build\temp.win32-2.7\Release\src\brisk.lib : fatal error LNK1120: 1 unresolved externals
error: command '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\link.exe"' failed with exit status 1120

Uncontrolled flailing: I thought maybe the libraries needed to be built, so I did a crash course (lots of crashing) with cmake + mingw - mingw + vc++ express 2010 as follows:

cmake gui: source: c:/brisk, build: c:/brisk/build cmake gui: configure for Visual Studio 10 cmake gui: use default options and generate (CMAKE_BACKWARDS_COMPATIBILITY, CMAKE_INSTALL_PREFIX, EXECUTABLE_OUTPUT_PATH, LIBRARY_OUTPUT_PATH)

VC++ Express 10: Change to Release and build the solution generated by cmake and get about 20 pages of what look like non-critical warnings followed by all succeeded. Note - no dlls are generated by this. It does generate the following libraries of similar size to the ones included with the download:

win32/lib/Release/
    agast_static.lib
    brisk_static.lib

Further flailing.

Relevant BRISK source file structure for reference:
build/ (empty)
include/brisk/
    brisk.h
    hammingsse.hpp
src
    brisk.cpp
    demo.cpp
thirdparty/agast/
    include/agast/
        agast5_8.h ....
        cvWrapper.h
    src/
        agast5_8.cc ...
    CMakeLists.txt
win32/
    bin/
        brisk.mexw32
        opencv_calib3d220.dll ...
    lib/
        agast_static.lib
        brisk_static.lib
CMakeLists.txt
FindOpenCV.cmake
Makefile

Ответы на вопрос(1)

Ваш ответ на вопрос