I am importing c++ code in a python project, everything seems to compile just fine however when importing my .pyx I get:
from AGCython import *
ImportError: /path/to/shared/object/AGCython.cpython-36m-x86_64-linux-gnu.so: undefined symbol: c_Stat_GetMeanAndVariance_double
In my AGCython.pyx I have:
cdef extern void c_Stat_GetMeanAndVariance_double (double* array, int nSize, double* mean, double* var)
and its python wrapper
def Stat_GetMeanAndVariance_double(np.ndarray[double, ndim=1, mode="c"] input not None):
cdef int m #nSize
m = input.shape[0]
cdef double mean, var
c_Stat_GetMeanAndVariance_double(&input[0], m, &mean, &var)
return mean, var
this cpp function is defined in AGc.cpp:
#include "AGc.h"
void c_Stat_GetMeanAndVariance_double(const double *aData, const int nSize, double &mean, double &var)
{
// Special case, small vector
if (nSize<=1)
{
var= 0;
if (nSize)
mean= *aData;
else
mean= 0;
return;
}
double s, ssqr;
Stat_GetSums_double(aData, nSize, s, ssqr);
mean= s/nSize;
var= Stat_GetVariance(s, ssqr, nSize);
return;
}
and AGc.h contains:
void c_Stat_GetMeanAndVariance_double(const double *aData, const int nSize, double &mean, double &var);
I my compilation script is this:
from distutils.core import setup
from Cython.Build import cythonize
from distutils.extension import Extension
import numpy
sourcefiles = ['AGCython.pyx', 'AGc.cpp']
extensions = [Extension("AGCython", sourcefiles)]
setup(
ext_modules = cythonize(extensions, annotate=True)
)
Which results in this gcc call:
gcc -pthread -B /home/ludvig/anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/ludvig/anaconda3/include/python3.6m -c AGc.cpp -o build/temp.linux-x86_64-3.6/AGc.o
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
g++ -pthread -shared -B /home/ludvig/anaconda3/compiler_compat -L/home/ludvig/anaconda3/lib -Wl,-rpath=/home/ludvig/anaconda3/lib -Wl,--no-as-needed -Wl,--sysroot=/ build/temp.linux-x86_64-3.6/AGCython.o build/temp.linux-x86_64-3.6/AGc.o -o /path/to/my/project/AGCython.cpython-36m-x86_64-linux-gnu.so
I don't understand what I've missed here, I don't think the warning is the problem from reading this question