gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 13:06:29 24 4
gpt4 key购买 nike

我制作了一个使用以下在线库的 .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>

最佳答案

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

Compile simpleTest.cpp errors

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

关于c++ - 编译 complex_Bessel_function 库 - 与 Fortran 代码链接 - mex 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42072584/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com