首页 > 解决方案 > 如何在 Matlab 中导入 C++ dll

问题描述

我正在努力在 Matlab (2019a) 中导入 C++ (2017) dll。

特别是,由于我不熟悉 C++,因此我尝试创建 https://github.com/MicrosoftDocs/cpp-docs/blob/master/docs/build/walkthrough-creating-and-using- 中定义的MathLibrary a-动态链接库-cpp.md。我根据指南创建了库,编译了 Debug 和 Release (x86),并且使用描述的 MathClient 导入工作正常。

但是,我尝试在 Matlab 中导入库(在将所需文件夹添加到当前路径之后):

        if libisloaded('MathLibrary') == 0
           handle = loadlibrary('MathLibrary.dll','MathLibrary.h');
        end

它会引发大量错误:

        Warning: Message from C preprocessor:
        cl : command line warning D9027: source file 'C:\Users\miche\source\repos\MathLibrary\Release\MathLibrary.lib' ignored
        cl : command line warning D9021 : no operation performed

        > In loadlibrary 
        Error loading library intermediate output follows.
        The actual error is at the end of this output.
        *********
        Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.30), passed through in regex; marked by <-- HERE in m/struct([^;,{(]*){ <-- HERE (.*?)\}([^;])*;/ at D:\Program Files\MATLAB\R2019a\toolbox\matlab\general\private\prototypes.pl line 912.
        Warning no reference to header 'MathLibrary' added with addheader was found in source.
        *********
        Error using loadlibrary
        Building MathLibrary_thunk_pcwin64 failed.  Compiler output is:
        cl -I"D:\Program Files\MATLAB\R2019a\extern\include" /Zp8  /W3
        /nologo  -I"D:\Program Files\MATLAB\R2019a\bin"
        -I"C:\Users\user\source\repos\MathLibrary\Release"
        "MathLibrary_thunk_pcwin64.c" -LD
        -Fe"MathLibrary_thunk_pcwin64.dll"
        MathLibrary_thunk_pcwin64.c
        C:\Users\miche\source\repos\MathLibrary\Release\MathLibrary.lib(1):
        error C2059: syntax error: '!'
        C:\Users\miche\source\repos\MathLibrary\Release\MathLibrary.lib(2):
        error C2018: character '0x60' unknown

然后就这样继续下去,有很多字符错误。我的代码有什么问题?我该如何解决这个问题?

标签: c++visual-studiomatlabdllimport

解决方案


推荐阅读