无法从 Matlab Coder 创建 .dll
Posted
技术标签:
【中文标题】无法从 Matlab Coder 创建 .dll【英文标题】:Can't create a .dll from Matlab Coder 【发布时间】:2015-08-05 19:28:05 【问题描述】:我正在尝试使用 Matlab Coder 工具将一些 matlab 代码转换为 c 动态库 (.dll)。我正在尝试一些简单的示例代码,但我不断收到相同的错误,我找不到解决方案。
我的代码是:
function y = lbryTest(x, z) %#codegen
%QUICKTEST Summary of this function goes here
% Detailed explanation goes here
y = 1.0;
a = x + z;
b = x * a;
y = b/3 + y;
end
我尝试过使用 coder 的应用版本以及命令:codegen -config:dll lbryTest -args 2.0, 5.0
和构建日志,包括错误,是:
1 C:/PROGRA~1/MATLAB/R2015a/sys/lcc64/lcc64/bin/lcc64 -c -w -noregistrylookup -nodeclspec -IC:/PROGRA~1/MATLAB/R2015a/sys/lcc64/lcc64/include64 -DMODEL=lbryTest -DHAVESTDIO -DUSE_RTMODEL -IC:/Users/shutchinson/Documents/MATLAB -IC:/Users/shutchinson/Documents/MATLAB/codegen/dll/lbryTest -IC:/PROGRA~1/MATLAB/R2015a/extern/include -IC:/PROGRA~1/MATLAB/R2015a/simulink/include -IC:/PROGRA~1/MATLAB/R2015a/rtw/c/src -IC:/PROGRA~1/MATLAB/R2015a/rtw/c/src/ext_mode/common -IC:/PROGRA~1/MATLAB/R2015a/rtw/c/ert -Fo"lbryTest_initialize.obj" "lbryTest_initialize.c"
2 C:/PROGRA~1/MATLAB/R2015a/sys/lcc64/lcc64/bin/lcc64 -c -w -noregistrylookup -nodeclspec -IC:/PROGRA~1/MATLAB/R2015a/sys/lcc64/lcc64/include64 -DMODEL=lbryTest -DHAVESTDIO -DUSE_RTMODEL -IC:/Users/shutchinson/Documents/MATLAB -IC:/Users/shutchinson/Documents/MATLAB/codegen/dll/lbryTest -IC:/PROGRA~1/MATLAB/R2015a/extern/include -IC:/PROGRA~1/MATLAB/R2015a/simulink/include -IC:/PROGRA~1/MATLAB/R2015a/rtw/c/src -IC:/PROGRA~1/MATLAB/R2015a/rtw/c/src/ext_mode/common -IC:/PROGRA~1/MATLAB/R2015a/rtw/c/ert -Fo"lbryTest_terminate.obj" "lbryTest_terminate.c"
3 C:/PROGRA~1/MATLAB/R2015a/sys/lcc64/lcc64/bin/lcc64 -c -w -noregistrylookup -nodeclspec -IC:/PROGRA~1/MATLAB/R2015a/sys/lcc64/lcc64/include64 -DMODEL=lbryTest -DHAVESTDIO -DUSE_RTMODEL -IC:/Users/shutchinson/Documents/MATLAB -IC:/Users/shutchinson/Documents/MATLAB/codegen/dll/lbryTest -IC:/PROGRA~1/MATLAB/R2015a/extern/include -IC:/PROGRA~1/MATLAB/R2015a/simulink/include -IC:/PROGRA~1/MATLAB/R2015a/rtw/c/src -IC:/PROGRA~1/MATLAB/R2015a/rtw/c/src/ext_mode/common -IC:/PROGRA~1/MATLAB/R2015a/rtw/c/ert -Fo"lbryTest.obj" "lbryTest.c"
4 C:/PROGRA~1/MATLAB/R2015a/sys/lcc64/lcc64/bin/lcc64 -c -w -noregistrylookup -nodeclspec -IC:/PROGRA~1/MATLAB/R2015a/sys/lcc64/lcc64/include64 -DMODEL=lbryTest -DHAVESTDIO -DUSE_RTMODEL -IC:/Users/shutchinson/Documents/MATLAB -IC:/Users/shutchinson/Documents/MATLAB/codegen/dll/lbryTest -IC:/PROGRA~1/MATLAB/R2015a/extern/include -IC:/PROGRA~1/MATLAB/R2015a/simulink/include -IC:/PROGRA~1/MATLAB/R2015a/rtw/c/src -IC:/PROGRA~1/MATLAB/R2015a/rtw/c/src/ext_mode/common -IC:/PROGRA~1/MATLAB/R2015a/rtw/c/ert -Fo"rt_nonfinite.obj" "rt_nonfinite.c"
5 C:/PROGRA~1/MATLAB/R2015a/sys/lcc64/lcc64/bin/lcc64 -c -w -noregistrylookup -nodeclspec -IC:/PROGRA~1/MATLAB/R2015a/sys/lcc64/lcc64/include64 -DMODEL=lbryTest -DHAVESTDIO -DUSE_RTMODEL -IC:/Users/shutchinson/Documents/MATLAB -IC:/Users/shutchinson/Documents/MATLAB/codegen/dll/lbryTest -IC:/PROGRA~1/MATLAB/R2015a/extern/include -IC:/PROGRA~1/MATLAB/R2015a/simulink/include -IC:/PROGRA~1/MATLAB/R2015a/rtw/c/src -IC:/PROGRA~1/MATLAB/R2015a/rtw/c/src/ext_mode/common -IC:/PROGRA~1/MATLAB/R2015a/rtw/c/ert -Fo"rtGetNaN.obj" "rtGetNaN.c"
6 C:/PROGRA~1/MATLAB/R2015a/sys/lcc64/lcc64/bin/lcc64 -c -w -noregistrylookup -nodeclspec -IC:/PROGRA~1/MATLAB/R2015a/sys/lcc64/lcc64/include64 -DMODEL=lbryTest -DHAVESTDIO -DUSE_RTMODEL -IC:/Users/shutchinson/Documents/MATLAB -IC:/Users/shutchinson/Documents/MATLAB/codegen/dll/lbryTest -IC:/PROGRA~1/MATLAB/R2015a/extern/include -IC:/PROGRA~1/MATLAB/R2015a/simulink/include -IC:/PROGRA~1/MATLAB/R2015a/rtw/c/src -IC:/PROGRA~1/MATLAB/R2015a/rtw/c/src/ext_mode/common -IC:/PROGRA~1/MATLAB/R2015a/rtw/c/ert -Fo"rtGetInf.obj" "rtGetInf.c"
7 C:/PROGRA~1/MATLAB/R2015a/sys/perl/win32/bin/perl.exe C:/PROGRA~1/MATLAB/R2015a/rtw/c/tools/mkvc_lnk.pl lbryTest.lnk lbryTest_initialize.obj lbryTest_terminate.obj lbryTest.obj rt_nonfinite.obj rtGetNaN.obj rtGetInf.obj lccstub.obj
8 "### Creating dynamic library "./lbryTest.dll" ..."
9 C:/PROGRA~1/MATLAB/R2015a/sys/lcc64/lcc64/bin/lcclnk64 -dll -entry LibMain -s -LC:/PROGRA~1/MATLAB/R2015a/sys/lcc64/lcc64/lib64 lbryTest.def -o ./lbryTest.dll @lbryTest.lnk
10 cannot open lccstub.obj
11 gmake: *** [lbryTest.dll] Error 1
12 The make command returned an error of 2
13 'An_error_occurred_during_the_call_to_make' is not recognized as an internal or external command,
14 operable program or batch file.
15
16 Error(s) encountered while building model "lbryTest":
17 ### Failed to generate all binary outputs.
我可以从这段代码中创建一个 .lib,但我需要一个 .dll,但事实证明这很困难。看起来我缺少一些目标文件或 matlab 找不到它,但我不知道该怎么办。
【问题讨论】:
也许你也应该发布你用来生成代码的命令。 发布整个构建日志也可能会有所帮助,包括编译 C 文件的行。是在codegen
目录下生成的文件lccstub.obj,默认codegen\dll\lbryTest
?
还要检查一下,codegen 目录的完整路径是否包含任何“特殊”字符?众所周知,诸如 $、&、非英文字符之类的东西会导致 gmake 出现问题。在这种情况下,联系MathWorks technical support 可能会有所帮助。
谢谢。由于某种原因,文件lccstub.c
似乎没有被编译为生成lccstub.obj
。为了快速解决问题,您可以考虑安装另一个 supported compiler。 This article 描述了安装和使用免费提供的 Microsoft Windows SDK 7.1 以与 MATLAB 一起使用。
lcstub.c 应该随 MATLAB 一起提供。但我仍然建议尝试使用 Windows SDK 来构建共享库。
【参考方案1】:
感谢 Ryan Livingston 提出的这个建议,我将把它变成官方答案
文件 lccstub.c(编译为 lccstub.obj)不在您的机器上,但它应该在。要修复它,您应该为 Matlab 安装支持的编译器。
Windows SDK 7.1 可从here免费获得
【讨论】:
以上是关于无法从 Matlab Coder 创建 .dll的主要内容,如果未能解决你的问题,请参考以下文章
无法使用 Matlab Coder 将 Matlab 代码转换为 C 代码