Created an empty c++ in visual studio 2017
added the following files with following C++ methods
//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 for 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"
*/
Added custom action for gfg.i file as below with output file name as gfg_wrap.c
$(SWIG_PATH)\swig.exe -python gfg.i
while compiling gfg.i file, it given two outputs gfg.py and gfg_wrap.c.
then i created Setup.py file with the following contents
# 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
with custom action as
C:\Python37\python_d.exe setup.py build_ext --inplace
this python directory contains swig.exe
after executing this, it generated an _gfg_d.cp37-win_amd64.pyd file in the project directory.
when given import gfg from CMD it shown the following error.
I was trying to access fact method from gfg.h Is there something iam missing out?

python.exefor Python 3.7 and it will work.