编译complex_Bessel_function库 - 与Fortran代码链接 - mex文件

时间:2017-02-06 16:26:21

标签: c++ fortran libraries mex bessel-functions

我制作了一个使用以下在线库的.cpp代码:

Complex_Bessel_functions

我想从我的代码中创建一个.mex文件。当我打字时:

mex GUSTAVsolution.cpp

Matlab给出了以下错误:

Error using mex
/tmp/mex_7456790284416_24518/GUSTAVsolution.o: In function `MIEsolution::Spherical_Hankel_function(unsigned int,
std::complex<double>, int)':
GUSTAVsolution.cpp:(.text+0x18c): undefined reference to `zbesh_wrap'
GUSTAVsolution.cpp:(.text+0x28e): undefined reference to `zbesh_wrap'
/tmp/mex_7456790284416_24518/GUSTAVsolution.o: In function `MIEsolution::Spherical_Bessel_function_2k(unsigned int,
std::complex<double>)':
GUSTAVsolution.cpp:(.text+0x3dc): undefined reference to `zbesy_wrap'
GUSTAVsolution.cpp:(.text+0x53d): undefined reference to `zbesj_wrap'
/tmp/mex_7456790284416_24518/GUSTAVsolution.o: In function `MIEsolution::Spherical_Bessel_function_1k(unsigned int,
std::complex<double>)':
GUSTAVsolution.cpp:(.text+0x7a0): undefined reference to `zbesj_wrap'
GUSTAVsolution.cpp:(.text+0x907): undefined reference to `zbesy_wrap'
/tmp/mex_7456790284416_24518/GUSTAVsolution.o: In function
`MIEsolution::Differentation_Spherical_Hankel_function(unsigned int, std::complex<double>, int)':
GUSTAVsolution.cpp:(.text+0xb32): undefined reference to `zbesh_wrap'
GUSTAVsolution.cpp:(.text+0xc4f): undefined reference to `zbesh_wrap'
GUSTAVsolution.cpp:(.text+0xd30): undefined reference to `zbesh_wrap'
GUSTAVsolution.cpp:(.text+0xe4d): undefined reference to `zbesh_wrap'
/tmp/mex_7456790284416_24518/GUSTAVsolution.o: In function
`MIEsolution::Differentation_Spherical_Bessel_function(unsigned int, std::complex<double>, int)':
GUSTAVsolution.cpp:(.text+0xfb8): undefined reference to `zbesj_wrap'
GUSTAVsolution.cpp:(.text+0x112b): undefined reference to `zbesy_wrap'
GUSTAVsolution.cpp:(.text+0x1303): undefined reference to `zbesj_wrap'
GUSTAVsolution.cpp:(.text+0x1476): undefined reference to `zbesy_wrap'
GUSTAVsolution.cpp:(.text+0x161a): undefined reference to `zbesy_wrap'
GUSTAVsolution.cpp:(.text+0x1787): undefined reference to `zbesj_wrap'
GUSTAVsolution.cpp:(.text+0x1935): undefined reference to `zbesy_wrap'
GUSTAVsolution.cpp:(.text+0x1aa2): undefined reference to `zbesj_wrap'
collect2: error: ld returned 1 exit status

我发现这些错误的一个功能是:

    complex<double> MIEsolution::Spherical_Bessel_function_2k(unsigned n,complex<double> z){

    complex<double> Sb2k;

        Sb2k = sph_besselY(n, z);

    return Sb2k;

}

关键是这个库将一些Fortran代码与C ++连接起来。例如,sph_besselY函数将调用相应的Fortran代码zbesy_wrap

我想以某种方式编译Fortran函数吗?我以与网页相同的方式安装了库。此外,我正在将库导入我的代码,如:

#include <complex_bessel.h>

1 个答案:

答案 0 :(得分:0)

要解决此问题,请按照此处的建议添加链接器标记-lcomplex_bessel

Compile simpleTest.cpp errors

Code :: Blocks IDE中的

我在Project->Build Options...->Linker Settings->Other linker options:文本框中设置了这个标志 对于mex,我不知道这个mex GUSTAVsolution.cpp -lcomplex_bessel是否会起作用,但是你肯定应该以某种方式添加这个链接器标志!