如何修复链接到 dll 的 mex 命令的错误

发布于 2025-01-11 08:52:01 字数 3670 浏览 0 评论 0原文

这是我的 mex 命令:

currentDir = cd;currentDir = regexp(currentDir, filesep, 'split');
ipath = ['-I' fullfile(currentDir{1:end-1},'eigen-3.4.0')];

mex(ipath,lpathFFTW,...
    'CXXFLAGS="$CXXFLAGS -march=native -std=c++14 -fno-math-errno -ffast-math -fopenmp -DNDEBUG"',...
    'LDFLAGS="$LDFLAGS -fopenmp"',...
    'CXXOPTIMFLAGS="-O3"',...
    'computeDASBMode.cpp','computeDAShelper.cpp',...
    '-outdir',outputFolder)

我尝试了以下操作作为 lpathFFTW 的选项,每个试验给出了相应的错误:

试验 1: libfftw3-3.dll 位于目标路径中

lpathFFTW = ['-L' fullfile(currentDir{1:end-1},'fftw-3.3.5-dll64','libfftw3-3.lib')];

错误:

Error using mex
C:\Users\nikun\AppData\Local\Temp\mex_516976837146_11436\computeDAShelper.obj:computeDAShelper.cpp:(.text+0x128b): undefined reference to `__imp_fftw_import_wisdom_from_filename'
C:\Users\nikun\AppData\Local\Temp\mex_516976837146_11436\computeDAShelper.obj:computeDAShelper.cpp:(.text+0x12f0): undefined reference to `__imp_fftw_plan_many_dft'
C:\Users\nikun\AppData\Local\Temp\mex_516976837146_11436\computeDAShelper.obj:computeDAShelper.cpp:(.text+0x135d): undefined reference to `__imp_fftw_export_wisdom_to_filename'
collect2.exe: error: ld returned 1 exit status

试用 2: 使用 matlab 根文件夹中的 fftw 库

lpathFFTW = ['-L',fullfile(matlabroot,'bin',computer('arch'),'libmwfftw3.lib')];

错误:

Error using mex
C:\Users\nikun\AppData\Local\Temp\mex_1088299880810_11436\computeDAShelper.obj:computeDAShelper.cpp:(.text+0x128b): undefined reference to `__imp_fftw_import_wisdom_from_filename'
C:\Users\nikun\AppData\Local\Temp\mex_1088299880810_11436\computeDAShelper.obj:computeDAShelper.cpp:(.text+0x12f0): undefined reference to `__imp_fftw_plan_many_dft'
C:\Users\nikun\AppData\Local\Temp\mex_1088299880810_11436\computeDAShelper.obj:computeDAShelper.cpp:(.text+0x135d): undefined reference to `__imp_fftw_export_wisdom_to_filename'
collect2.exe: error: ld returned 1 exit status

TLDR:我尝试使用 fftw 网站上的 dll 或 matlab 中的 dll 编译链接 FFTW 库的 mex 函数。两者似乎都失败了。

更新 我尝试这样做是为了回应 @Cris Luengo 的评论:

lpathFFTW = ['-L',fullfile(matlabroot,'bin',computer('arch'))];

mex(ipath,lpathFFTW,'-llibmwfftw3.lib',...
    'CXXFLAGS="$CXXFLAGS -march=native -std=c++14 -fno-math-errno -ffast-math -fopenmp -DNDEBUG"',...
    'LDFLAGS="$LDFLAGS -fopenmp"',...
    'CXXOPTIMFLAGS="-O3"',...
    'computeDASBMode.cpp','computeDAShelper.cpp',...
    '-outdir',outputFolder)

产生以下错误:

Error using mex
MEX cannot find library 'libmwfftw3', specified with the -l option.
 MEX searched for a file with one of the following names:
 libmwfftw3.lib
liblibmwfftw3.lib
 Verify the library name is correct. If the library is not
 on the existing path, specify the path with the -L option.

更新 2 我也尝试过这个,但出现以下错误:

lpathFFTW = ['-L',fullfile(matlabroot,'bin',computer('arch'))];

mex(ipath,lpathFFTW,...
    'CXXFLAGS="$CXXFLAGS -march=native -std=c++14 -fno-math-errno -ffast-math -fopenmp -DNDEBUG"',...
    'LDFLAGS="$LDFLAGS -fopenmp"',...
    'LINKLIBS="$LINKLIBS -llibmwfftw3"',...
    'CXXOPTIMFLAGS="-O3"',...
    'computeDASBMode.cpp','computeDAShelper.cpp',...
    '-outdir',outputFolder,'-v')
C:/ProgramData/MATLAB/SupportPackages/R2020b/3P.instrset/mingw_w64.instrset/bin/../lib/gcc/x86_64-w64-mingw32/6.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -llibmwfftw3
collect2.exe: error: ld returned 1 exit status

This is my mex command:

currentDir = cd;currentDir = regexp(currentDir, filesep, 'split');
ipath = ['-I' fullfile(currentDir{1:end-1},'eigen-3.4.0')];

mex(ipath,lpathFFTW,...
    'CXXFLAGS="$CXXFLAGS -march=native -std=c++14 -fno-math-errno -ffast-math -fopenmp -DNDEBUG"',...
    'LDFLAGS="$LDFLAGS -fopenmp"',...
    'CXXOPTIMFLAGS="-O3"',...
    'computeDASBMode.cpp','computeDAShelper.cpp',...
    '-outdir',outputFolder)

I've tried the following things as an option for lpathFFTW with the corresponding errors each trial gives:

Trial 1:
where libfftw3-3.dll is in the target path

lpathFFTW = ['-L' fullfile(currentDir{1:end-1},'fftw-3.3.5-dll64','libfftw3-3.lib')];

error:

Error using mex
C:\Users\nikun\AppData\Local\Temp\mex_516976837146_11436\computeDAShelper.obj:computeDAShelper.cpp:(.text+0x128b): undefined reference to `__imp_fftw_import_wisdom_from_filename'
C:\Users\nikun\AppData\Local\Temp\mex_516976837146_11436\computeDAShelper.obj:computeDAShelper.cpp:(.text+0x12f0): undefined reference to `__imp_fftw_plan_many_dft'
C:\Users\nikun\AppData\Local\Temp\mex_516976837146_11436\computeDAShelper.obj:computeDAShelper.cpp:(.text+0x135d): undefined reference to `__imp_fftw_export_wisdom_to_filename'
collect2.exe: error: ld returned 1 exit status

Trial 2:
using the fftw library from matlab's root folder

lpathFFTW = ['-L',fullfile(matlabroot,'bin',computer('arch'),'libmwfftw3.lib')];

error:

Error using mex
C:\Users\nikun\AppData\Local\Temp\mex_1088299880810_11436\computeDAShelper.obj:computeDAShelper.cpp:(.text+0x128b): undefined reference to `__imp_fftw_import_wisdom_from_filename'
C:\Users\nikun\AppData\Local\Temp\mex_1088299880810_11436\computeDAShelper.obj:computeDAShelper.cpp:(.text+0x12f0): undefined reference to `__imp_fftw_plan_many_dft'
C:\Users\nikun\AppData\Local\Temp\mex_1088299880810_11436\computeDAShelper.obj:computeDAShelper.cpp:(.text+0x135d): undefined reference to `__imp_fftw_export_wisdom_to_filename'
collect2.exe: error: ld returned 1 exit status

TLDR: I tried to compile a mex function linking the FFTW libraries using either the dll from fftw's website or the dll from matlab. Both seem to fail.

Update
I tried this in response to @Cris Luengo's comment:

lpathFFTW = ['-L',fullfile(matlabroot,'bin',computer('arch'))];

mex(ipath,lpathFFTW,'-llibmwfftw3.lib',...
    'CXXFLAGS="$CXXFLAGS -march=native -std=c++14 -fno-math-errno -ffast-math -fopenmp -DNDEBUG"',...
    'LDFLAGS="$LDFLAGS -fopenmp"',...
    'CXXOPTIMFLAGS="-O3"',...
    'computeDASBMode.cpp','computeDAShelper.cpp',...
    '-outdir',outputFolder)

yielding the following error:

Error using mex
MEX cannot find library 'libmwfftw3', specified with the -l option.
 MEX searched for a file with one of the following names:
 libmwfftw3.lib
liblibmwfftw3.lib
 Verify the library name is correct. If the library is not
 on the existing path, specify the path with the -L option.

Update 2
I also tried this but got the following error:

lpathFFTW = ['-L',fullfile(matlabroot,'bin',computer('arch'))];

mex(ipath,lpathFFTW,...
    'CXXFLAGS="$CXXFLAGS -march=native -std=c++14 -fno-math-errno -ffast-math -fopenmp -DNDEBUG"',...
    'LDFLAGS="$LDFLAGS -fopenmp"',...
    'LINKLIBS="$LINKLIBS -llibmwfftw3"',...
    'CXXOPTIMFLAGS="-O3"',...
    'computeDASBMode.cpp','computeDAShelper.cpp',...
    '-outdir',outputFolder,'-v')
C:/ProgramData/MATLAB/SupportPackages/R2020b/3P.instrset/mingw_w64.instrset/bin/../lib/gcc/x86_64-w64-mingw32/6.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -llibmwfftw3
collect2.exe: error: ld returned 1 exit status

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文