Создан пустой c ++ в visual studio 2017
добавлены следующие файлы со следующими методами C ++
// gfg.c
#include <stdio.h>
#include <math.h>
//our header file
#include "gfg.h"
#define ll long long
double myvar = 3.4;
// calculate factorial
ll int fact(ll int n)
{
if (n <= 1)
return 1;
else
return (n * fact(n - 1));
}
//find mod
int my_mod(int n, int m)
{
return(n % m);
}
// gfg.h
#pragma once
long long int fact(long long int n);
int my_mod(int n, int m);
// gfg.i для swig
/* file : gfg.i */
/* name of module to use*/
%module gfg
%{
/* Every thing in this file is being copied in
wrapper file. We include the C header file necessary
to compile the interface */
#include "gfg.h"
/* variable declaration*/
double myvar;
%}
/* explicitly list functions and variables to be interfaced */
double myvar;
long long int fact(long long int n1);
int my_mod(int m, int n);
/* or if we want to interface all functions then we can simply
include header file like this -
%include "gfg.h"
*/
Добавлено настраиваемое действие для файла gfg.i, как показано ниже, с именем выходного файла gfg_wrap.c
$(SWIG_PATH)\swig.exe -python gfg.i
при компиляции gfg.я подал, он дал два выхода gfg.py
и gfg_wrap.c
.
затем я создал Setup.py
файл со следующим содержимым
# File : setup.py
from distutils.core import setup, Extension
#name of module
name = "gfg"
#version of module
version = "1.0"
# specify the name of the extension and source files
# required to compile this
ext_modules = Extension(name='_gfg',sources=["gfg.i","gfg.c"])
setup(name=name,
version=version,
ext_modules=[ext_modules])
#C:\Python37\python_d.exe setup.py build_ext --inplace
с настраиваемым действием как
C:\Python37\python_d.exe setup.py build_ext --inplace
этот каталог python содержит swig.exe
после выполнения этого он сгенерировал файл _gfg_d.cp37-win_amd64.pyd
в каталоге проекта.
при выдаче import gfg
из CMD он показал следующую ошибку.
Я пытался получить доступ к fact
методу из gfg.h
Есть ли что-то, что я пропустил?