Don
Don

Reputation: 11

How are .pyd files made from C++ projects?

My current goal is to get this repo, CV-camera-finder, to be compatible with Python 3.10. In the README file, the original publisher says

A simple function to find a connected camera list with media foundation. This is just a modified code of a sample found in https://github.com/Microsoft/Windows-classic-samples/tree/master/Samples/Win7Samples/multimedia/mediafoundation/MFCaptureToFile to use in python.

Download pymf.pyd(32-bit -> file in folder 32, 64-bit -> ...) to your PYTHONPATH to just use it. If you want to modify it, edit cpp files and rebuild it.

My knowledge of Python is intermediate and C++ beginner at best. I downloaded Visual Studio 2022 and attempted to rebuild it myself with no success. I used his cap.cpp and pymf.cpp files, as well as the capture.h files from the referenced Media Foundation samples as I was under the impression based off of includes that I didn't need anything else. I pointed my include of Python.h to the one located in the 3.10 include folders assuming that would fix the problem.

I ran into multiple issues. The first being

unable to open 'python310.lib'

I added an additional library dependency pointing to the 3.10 libs folder. After doing that, here are the errors I am getting now.

LNK2001 unresolved external symbol main
LNK1120 1 unresolved externals

I am clearly over my head with this but I would really like to get this working for Python 3.10. Could anyone provide an steps/advice/tutorials/etc on getting this built and made into a .pyd?

Upvotes: 1

Views: 1452

Answers (2)

Minxin Yu - MSFT
Minxin Yu - MSFT

Reputation: 4304

LNK2001 unresolved external symbol main

The program lacks an entry function. If you don't want to use main, please specify the configuration type of the project as lib or dll.

Upvotes: 0

dmatos2012
dmatos2012

Reputation: 93

Make sure you change your project settings in Visual Studio following this link writing python extension. Specifically the Additional Include Directories and Additional Library Directories under linker. Also, look at the target file extension is pyd and dll for configuration type.

If you have that, along with the capture.h from the MF github you have, it should work. Also, I added the following lines to my capture.h else VS wouldnt find some of the libraries.

#pragma once
#include <mfreadwrite.h>
#include <Dbt.h>

Tested with python3.8 and windows 10.

Upvotes: 0

Related Questions