我遇到以下错误,希望能帮助您跟踪为什么会发生这种情况:
回溯(最近通话最近): 文件“ wterms_1p.py”,第16行,在 从w2_integration.integrate_cf导入v ImportError:dlopen(/Users/ian/Dropbox/Frohlich/linkedcluster/w2_integration/integrate_cf.so,2):找不到符号:__ZN9Integrate1hEddPSt7complexIdE 引用自:/Users/ian/Dropbox/Frohlich/linkedcluster/w2_integration/integrate_cf.so 预期于:平面名称空间 在/Users/ian/Dropbox/Frohlich/linkedcluster/w2_integration/integrate_cf.so
在某些背景下,我的代码项目包括C ++库和一个main.cpp文件,我用它来测试这些库是否正常工作。这些是通过此Makefile编译的:
CC=mpic++ -Wl,-rpath,/Users/ian/anaconda2/lib/
all: libdblquad.so libintegrate.so w2
libdblquad.so: dblquad.cpp dblquad.h
$(CC) -O3 -std=c++14 -fPIC dblquad.cpp -lgsl -lgslcblas -shared -o libdblquad.so -Wl,-rpath,.
libintegrate.so: coefficients.cpp integrate.cpp integrate.h arithmetic.h coefficients.h Complex.h
$(CC) -O3 -std=c++14 -fPIC coefficients.cpp integrate.cpp -L. -ldblquad -lfaddeeva -lgsl -shared -o libintegrate.so -Wl,-rpath,.
w2: main.cpp libintegrate.so libdblquad.so
$(CC) -O3 -std=c++14 main.cpp -L. -lintegrate -lgsl -lgslcblas -Wl,-rpath,/Users/ian/Dropbox/Frohlich/linkedcluster/w2_integration/
当我运行./a.out(生成的可执行文件)时,一切正常。但是,当我随后调用下面的Cython程序中定义的函数v时:
# cython: boundscheck=False, wraparound=False, nonecheck=False, cdivision=True, profile=True, linetrace=True
# distutils: language = c++
"""nmats.py"""
from libcpp.vector cimport vector
import numpy as np
cimport numpy as cnp
def v(k, t, n0):
tt = t.ravel()
return np.asarray(cf(k, tt, n0))
cdef extern from "integrate.h":
void integrate_cf(double k, double* t, complex* integrated_cf, int size, double n0)
cdef complex[:] cf(double k, double[:] t, double n0):
cdef complex[:] integrated_cf = np.ascontiguousarray(np.zeros_like(t, dtype=np.complex))
integrate_cf(k, &t[0], &integrated_cf[0], t.size, n0)
return integrated_cf
通过setup.py编译:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
import numpy
import os
os.environ["CC"] = "mpic++"
os.environ["CXX"] = "mpic++"
extensions = [
Extension("integrate_cf", ["integrate_cf.pyx"], extra_compile_args=["-O3", "-std=c++14"], extra_link_args=["-L"+os.getcwd(), "-L/usr/local/lib", "-Wl,-rpath,"+os.getcwd(), "-lintegrate", "-lgsl", "-lgslcblas"])]
ext_modules = cythonize(extensions)
setup(name="intcf", language='c++', ext_modules=ext_modules, include_dirs=[numpy.get_include()])
我收到本文顶部显示的“找不到符号”错误。有关更多信息,main.cpp(它会导致可执行的工作文件)调用Integrated_cf:
void integrate_cf(double k, double* s, Complex* val, int size, double n0)
{
Integrate integrate(n0);
MPI_Init(0, 0);
for( int i = 0; i < size; i++ )
{
//cout << s[i] << endl;
int status = integrate.h(k, s[i], &(val[i]));
if( status < 0 )
break;
}
}
同样,如上所示,上面的Cython程序也调用了Integrated_cf。 “ c ++ filt -n _ZN9Integrate1hEddPSt7complexIdE”的输出为:
Integrate::h(double, double, std::complex<double>*)
此函数在integration.h中声明,并在integrate.cpp中定义。知道为什么我的C ++可执行文件正常工作时我的Cython程序不能工作吗?