MATLAB CREATE DLL:命令 'link' 以 return 值“1”退出

MATLAB CREATE DLL: The command 'link' exited with a return value '1'

问题:想在 LABVIEW 中使用 MATLAB DLL

问题:低于错误

Building with 'Microsoft Visual C++ 2017 (C)'.
cl /c -MD -Zp8 -GR -W3 -EHsc- -Zc:wchar_t- -nologo -O2 -DNDEBUG /DMATLAB_DEFAULT_RELEASE=R2017b  /DUSE_MEX_CMD   /DMSVC /DIBMPC /D_CRT_SECURE_NO_DEPRECATE -I"D:\Program Files\MATLAB\R2020a\extern\include" -I"D:\Program Files\MATLAB\R2020a\extern\include\win64" "C:\Users\SHUBHAM\Documents\MATLAB\examplescriptdll\exampleWrapper.c" /FoC:\Users\SHUBHAM\AppData\Local\Temp\mex_18529067976172_19860\exampleWrapper.obj
exampleWrapper.c

link "/nologo /manifest /DLL -called_from_matlab    C:\Users\SHUBHAM\AppData\Local\Temp\mex_18529067976172_19860\exampleWrapper.obj  exampleScript.lib  /MACHINE:AMD64 /LIBPATH:"D:\Program Files\MATLAB\R2020a\extern\lib\win64\microsoft" mclmcrrt.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /out:exampleWrapper.exe
Error using mbuild (line 166)
Unable to complete successfully.
The command 'link' exited with a return value '1'

我试过了:https://forums.ni.com/t5/Example-Code/Walkthrough-for-Creating-a-MATLAB-DLL-That-Can-Be-Called-in/ta-p/3882891?profile.language=en

创建 DLL 文件并在 Labview 中使用它

这是我的 exampleScript.m 文件

function [sumone]=exampleScript(arr)
sumone=arr+1;
end

我用这个命令创建了DLL文件

mcc -v -B csharedlib:exampleScript exampleScript.m

并且如 doc 中所写,

This is not a native C type, which is what LabVIEW knows how to interface with. LabVIEW does not
know what to do with these types, which will pose problems for us later.

所以他们说要使用这个命令

mbuild -v exampleWrapper.c exampleScript.lib LINKFLAGS="$LINKFLAGS /DLL
/DEF:exampleWrapper.def" LDEXT=".dll"" CMDLINE250="mt -outputresource:$EXE';'2 -
manifest $MANIFEST"

同时创建 3 个新文件 exampleWrapper.C、exampleWrapper.h、exampleWrapper.def exampleWrapper.c

#include<stdio.h>
#include "exampleScript.h"
void loadExampleScript(void) {
    exampleScriptInitialize();
}
void unloadExampleScript(void) {
    exampleScriptTerminate();
}
int wmlfExampleScript(double* c2dArray, int numRows, int numColumns){
    int nargout=1;
    int result=1;
    mxArray *mIn2dArray;
    mxArray *mOut2Array=NULL;
    mIn2dArray=mxCreateDoubleMatrix(numRows, numColumns, mxREAL);
    memcpy(mxGetPr(mIn2dArray), c2dArray, numRows*numColumns*sizeof(double));
    result=mlfExampleScript(nargout, &mOut2Array, mIn2dArray);
    memcpy(c2dArray, mxGetPr(mOut2Array), numRows*numColumns*sizeof(double));
    mxDestroyArray(mIn2dArray);
    mxDestroyArray(mOut2Array);
    
    return result;
}

exampleWrapper.h

void loadExampleScript(void);
void unloadExampleScript(void);
int wmlfExampleScript(double* c2dArray, int numRows, int numColumns);

exampleWrapper.def

LIBRARY exampleWrapper
EXPORTS
loadExampleScript
unloadExampleScript
wmlfExampleScript

运行 它在一行中解决了这个问题

mbuild -v exampleWrapper.c exampleScript.lib LINKFLAGS="$LINKFLAGS /DLL /DEF:exampleWrapper.def" LDEXT=".dll" CMDLINE250="mt -outputresource:$EXE';'2 -manifest $MANIFEST"