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

2 views (last 30 days)
PROBLEM: WANT TO USE A MATLAB DLL IN LABVIEW
ISSUE: BELOW ERR
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'
I TRIED: https://forums.ni.com/t5/Example-Code/Walkthrough-for-Creating-a-MATLAB-DLL-That-Can-Be-Called-in/ta-p/3882891?profile.language=en
to create a DLL file and use it in Labview
this is my exampleScript.m file
function [sumone]=exampleScript(arr)
sumone=arr+1;
end
I used this command to create DLL files
mcc -v -B csharedlib:exampleScript exampleScript.m
and as written in doc[ATTACHMENT] that
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.
so they said to use this command
mbuild -v exampleWrapper.c exampleScript.lib LINKFLAGS="$LINKFLAGS /DLL
/DEF:exampleWrapper.def" LDEXT=".dll"" CMDLINE250="mt -outputresource:$EXE';'2 -
manifest $MANIFEST"
while creating 3 new files 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

Accepted Answer

shubham kumar gupta
shubham kumar gupta on 4 Feb 2021
Running it in a single line solev this issue 😂
mbuild -v exampleWrapper.c exampleScript.lib LINKFLAGS="$LINKFLAGS /DLL /DEF:exampleWrapper.def" LDEXT=".dll" CMDLINE250="mt -outputresource:$EXE';'2 -manifest $MANIFEST"

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!