Howto: mingw-w64 Add-on generated mex function that uses a mingw-w64 generated DLL (R2018b)

8 次查看(过去 30 天)
The matlab compiler is the mingw-w64 Add on.
To generate the dll, also system wide mingw-w64 installation is done.
I'm able to generate the mex funtion (at the end the toolchain is described)
After executing the file_mex, the dll is said not to be found, but the dll is in the current directory and in the windows's & matlab path.
'file_mex.mexw64': Missing dependent shared libraries:
'file.dll' required by 'file_mex.mexw64'.
loading the dll with loadlibrary says that
'file_mex.dll' has different architecture than the host.
Note that loadlibrary finds file.dll without problems.
My compiling toolchain:
!gcc -c -DBUILDING_EXAMPLE_DLL file.c
!gcc -shared -o file.dll file.o -Wl,--output-def,file.def,--out-implib,libfile.a
!"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\bin\Hostx64\x64\"lib /def:file.def
mex file_mex.c -L. -lfile -R2018a

采纳的回答

Javier Ros
Javier Ros 2018-11-3
The question was originated by an improper installation of system wide mingw-w64, I did mistakenly installed a 32 bit version (msys/mingw).
My other proposed solution, was working just because I was using the MATLAB Add-on provided mingw-w64 compiler, something limited if one intends to develop C libraries to be later interfaced with MATLAB mex files.
The following link can be helpful for those anew in this context .
So, after installing MSYS2 64 bit and gcc using its package management system pacman, the following instructions will work as expected:
Input:
!gcc -c shrlibsample.c
!gcc -o shrlibsample.dll shrlibsample.o -s -shared -Wl,--subsystem,windows,--out-implib,"shrlibsample.lib"
mex -v -g myAddStructByRef.c shrlibsample.lib
struct.p1 = 4; struct.p2 = 7.3; struct.p3 = -290;
[res,st] = myAddStructByRef(struct)
Output: C Struct: p1: 4.000000 p2: 7 p3: -290
Calculated sum: -279.000000
res =
struct with fields:
p1: 5.5000
p2: 1234
p3: 12345678
st =
-279
For anybody trying to reprodue this, I nave removed mex references from shrlibsample.c

更多回答(1 个)

Javier Ros
Javier Ros 2018-10-27
编辑:Javier Ros 2018-10-31
Solved!,
Instructions:
  • I've setup mbuild for MinGW-w64
>> mbuild --setup
  • I've compile the dll using mbuild (need to add -lmex LDTYPE="-shared" in the command line)
mbuild -v -g shrlibsample.c -lmex LDTYPE="-shared" LDEXT=".dll"
  • I've compiled the mex as before
mex -v -g myAddStructByRef.c shrlibsample.lib
  • Now it runs correctly.
%-----------
Full output of the proccess for reference:
>> clear all
>> !del shrlibsample.dll shrlibsample.lib
>> mbuild -v -g shrlibsample.c -lmex LDTYPE="-shared" LDEXT=".dll"
Verbose mode is on.
... Looking for compiler 'MinGW64 Compiler (C)' ...
... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset').
... Looking for file 'C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\gcc.exe' ...Yes.
... Looking for folder 'C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset' ...Yes.
Found installed compiler 'MinGW64 Compiler (C)'.
Set PATH = C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin;C:\Program Files\MATLAB\R2018b\extern\include\win64;C:\Program Files\MATLAB\R2018b\extern\include;C:\Program Files\MATLAB\R2018b\simulink\include;C:\Program Files\MATLAB\R2018b\lib\win64;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\MATLAB\R2018b\runtime\win64;C:\Program Files\MATLAB\R2018b\bin;C:\Program Files\PuTTY\;C:\Users\Javier Ros\AppData\Local\Microsoft\WindowsApps;C:\Users\Javier Ros\Desktop\animatelib\bin;C:\Users\Javier Ros\Desktop\OpenSceneGraph-3.4.1-VC2017-64\bin;C:\Program Files\MATLAB\R2018b\bin\win64;C:\Users\Javier Ros\AppData\Local\Programs\MiKTeX 2.9\miktex\bin\x64\;C:\Program Files\OpenSCAD;C:\MinGW\bin
Set INCLUDE = C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\include;;C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\include;;
Set LIB = C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\lib;;C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\lib;;
Set MW_TARGET_ARCH = win64;win64;
Set LIBPATH = C:\Program Files\MATLAB\R2018b\extern\lib\win64;C:\Program Files\MATLAB\R2018b\extern\lib\win64;
Options file details
-------------------------------------------------------------------
Compiler location: C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset
Options file: C:\Users\Javier Ros\AppData\Roaming\MathWorks\MATLAB\R2018b\MBUILD_C_win64.xml
CMDLINE1 : C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\gcc -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -m64 -I"C:\Program Files\MATLAB\R2018b/extern/include" -I"C:\Program Files\MATLAB\R2018b/simulink/include" -I"C:\Program Files\MATLAB\R2018b/extern\lib\win64\mingw64" -I"C:\Program Files\MATLAB\R2018b\extern\include\win64" -fexceptions -fno-omit-frame-pointer -g "C:\Users\Javier Ros\Desktop\caca\caca\shrlibsample.c" -o C:\Users\JAVIER~1\AppData\Local\Temp\mex_2295511870894822_9892\shrlibsample.obj
CMDLINE2 : C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\gcc -m64 -Wl,--no-undefined,--out-implib,"shrlibsample.lib" -shared -g C:\Users\JAVIER~1\AppData\Local\Temp\mex_2295511870894822_9892\shrlibsample.obj -llibmex -L"C:\Program Files\MATLAB\R2018b\extern\lib\win64\mingw64" -lmclmcrrt -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 -o shrlibsample.dll
CC : C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\gcc
COMPILER : C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\gcc
DEFINES : -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -m64
MATLABMEX :
CFLAGS : -fexceptions -fno-omit-frame-pointer
INCLUDE : -I"C:\Program Files\MATLAB\R2018b/extern/include" -I"C:\Program Files\MATLAB\R2018b/simulink/include" -I"C:\Program Files\MATLAB\R2018b/extern\lib\win64\mingw64" -I"C:\Program Files\MATLAB\R2018b\extern\include\win64"
COPTIMFLAGS : -O2 -fwrapv -DNDEBUG
CDEBUGFLAGS : -g
LD : C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\gcc
LINKER : C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\gcc
LDTYPE : -shared
LDFLAGS : -m64 -Wl,--no-undefined,--out-implib,"shrlibsample.lib"
LINKEXPORT :
LINKEXPORTVER :
LIBLOC : C:\Program Files\MATLAB\R2018b\extern\lib\win64\mingw64
LINKLIBS : -llibmex -L"C:\Program Files\MATLAB\R2018b\extern\lib\win64\mingw64" -lmclmcrrt -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32
LDOPTIMFLAGS : -s
LDDEBUGFLAGS : -g
OBJEXT : .obj
LDEXT : .dll
SETENV : set COMPILER=C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\gcc
set CXXCOMPILER=C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\g++
set COMPFLAGS=-c -fexceptions -fno-omit-frame-pointer -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -m64
set CXXCOMPFLAGS=-c -fexceptions -fno-omit-frame-pointer -std=c++11 -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -m64
set OPTIMFLAGS=-O2 -fwrapv -DNDEBUG
set DEBUGFLAGS=-g
set LINKER=C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\gcc
set CXXLINKER=C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\g++
set LINKFLAGS=-m64 -Wl,--no-undefined,--out-implib,"shrlibsample.lib" -shared -lmex -llibmex -L"C:\Program Files\MATLAB\R2018b\extern\lib\win64\mingw64" -lmclmcrrt -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32
set LINKDEBUGFLAGS=-g
set NAME_OUTPUT=-o "%OUTDIR%%MEX_NAME%%MEX_EXT%"
MINGWROOT : C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset
MATLABROOT : C:\Program Files\MATLAB\R2018b
ARCH : win64
LINKTYPE :
SRC : "C:\Users\Javier Ros\Desktop\caca\caca\shrlibsample.c"
OBJ : C:\Users\JAVIER~1\AppData\Local\Temp\mex_2295511870894822_9892\shrlibsample.obj
OBJS : C:\Users\JAVIER~1\AppData\Local\Temp\mex_2295511870894822_9892\shrlibsample.obj
SRCROOT : C:\Users\Javier Ros\Desktop\caca\caca\shrlibsample
DEF : C:\Users\JAVIER~1\AppData\Local\Temp\mex_2295511870894822_9892\shrlibsample.def
EXP : "shrlibsample.exp"
LIB : "shrlibsample.lib"
EXE : shrlibsample.dll
ILK : "shrlibsample.ilk"
MANIFEST : "shrlibsample.dll.manifest"
TEMPNAME : shrlibsample
EXEDIR :
EXENAME : shrlibsample
OPTIM : -g
LINKOPTIM : -g
-------------------------------------------------------------------
Building with 'MinGW64 Compiler (C)'.
C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\gcc -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -m64 -I"C:\Program Files\MATLAB\R2018b/extern/include" -I"C:\Program Files\MATLAB\R2018b/simulink/include" -I"C:\Program Files\MATLAB\R2018b/extern\lib\win64\mingw64" -I"C:\Program Files\MATLAB\R2018b\extern\include\win64" -fexceptions -fno-omit-frame-pointer -g "C:\Users\Javier Ros\Desktop\caca\caca\shrlibsample.c" -o C:\Users\JAVIER~1\AppData\Local\Temp\mex_2295511870894822_9892\shrlibsample.obj
C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\gcc -m64 -Wl,--no-undefined,--out-implib,"shrlibsample.lib" -shared -g C:\Users\JAVIER~1\AppData\Local\Temp\mex_2295511870894822_9892\shrlibsample.obj -llibmex -L"C:\Program Files\MATLAB\R2018b\extern\lib\win64\mingw64" -lmclmcrrt -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 -o shrlibsample.dll
>> mex -v -g myAddStructByRef.c shrlibsample.lib
Verbose mode is on.
... Looking for compiler 'MinGW64 Compiler (C)' ...
... Looking for environment variable 'MW_MINGW64_LOC' ...Yes ('C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset').
... Looking for file 'C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\gcc.exe' ...Yes.
... Looking for folder 'C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset' ...Yes.
Found installed compiler 'MinGW64 Compiler (C)'.
Set PATH = C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin;C:\Program Files\MATLAB\R2018b\extern\include\win64;C:\Program Files\MATLAB\R2018b\extern\include;C:\Program Files\MATLAB\R2018b\simulink\include;C:\Program Files\MATLAB\R2018b\lib\win64;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\MATLAB\R2018b\runtime\win64;C:\Program Files\MATLAB\R2018b\bin;C:\Program Files\PuTTY\;C:\Users\Javier Ros\AppData\Local\Microsoft\WindowsApps;C:\Users\Javier Ros\Desktop\animatelib\bin;C:\Users\Javier Ros\Desktop\OpenSceneGraph-3.4.1-VC2017-64\bin;C:\Program Files\MATLAB\R2018b\bin\win64;C:\Users\Javier Ros\AppData\Local\Programs\MiKTeX 2.9\miktex\bin\x64\;C:\Program Files\OpenSCAD;C:\MinGW\bin
Set INCLUDE = C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\include;;C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\include;;
Set LIB = C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\lib;;C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\lib;;
Set MW_TARGET_ARCH = win64;win64;
Set LIBPATH = C:\Program Files\MATLAB\R2018b\extern\lib\win64;C:\Program Files\MATLAB\R2018b\extern\lib\win64;
Options file details
-------------------------------------------------------------------
Compiler location: C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset
Options file: C:\Users\Javier Ros\AppData\Roaming\MathWorks\MATLAB\R2018b\mex_C_win64.xml
CMDLINE2 : C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\gcc -m64 -Wl,--no-undefined -shared -static -g -Wl,"C:\Program Files\MATLAB\R2018b/extern/lib/win64/mingw64/exportsmexfileversion.def" C:\Users\JAVIER~1\AppData\Local\Temp\mex_2295589744729364_9892\myAddStructByRef.obj C:\Users\JAVIER~1\AppData\Local\Temp\mex_2295589744729364_9892\c_mexapi_version.obj shrlibsample.lib -L"C:\Program Files\MATLAB\R2018b\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas -o myAddStructByRef.mexw64
CC : C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\gcc
COMPILER : C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\gcc
DEFINES : -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -m64 -DMATLAB_MEX_FILE
MATLABMEX : -DMATLAB_MEX_FILE
CFLAGS : -fexceptions -fno-omit-frame-pointer
INCLUDE : -I"C:\Program Files\MATLAB\R2018b/extern/include" -I"C:\Program Files\MATLAB\R2018b/simulink/include" -I"C:\Program Files\MATLAB\R2018b/extern\lib\win64\mingw64"
COPTIMFLAGS : -O2 -fwrapv -DNDEBUG
CDEBUGFLAGS : -g
LD : C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\gcc
LINKER : C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\gcc
LDTYPE : -shared -static
LDFLAGS : -m64 -Wl,--no-undefined
LINKEXPORT : -Wl,"C:\Program Files\MATLAB\R2018b/extern/lib/win64/mingw64/mexFunction.def"
LINKEXPORTVER : -Wl,"C:\Program Files\MATLAB\R2018b/extern/lib/win64/mingw64/exportsmexfileversion.def"
LIBLOC : C:\Program Files\MATLAB\R2018b\extern\lib\win64\mingw64
LINKLIBS : shrlibsample.lib -L"C:\Program Files\MATLAB\R2018b\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas
LDOPTIMFLAGS : -s
LDDEBUGFLAGS : -g
OBJEXT : .obj
LDEXT : .mexw64
SETENV : set COMPILER=C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\gcc
set CXXCOMPILER=C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\g++
set COMPFLAGS=-c -fexceptions -fno-omit-frame-pointer -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -m64 -DMATLAB_MEX_FILE -DMATLAB_MEX_FILE
set CXXCOMPFLAGS=-c -fexceptions -fno-omit-frame-pointer -std=c++11 -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -m64 -DMATLAB_MEX_FILE -DMATLAB_MEX_FILE
set OPTIMFLAGS=-O2 -fwrapv -DNDEBUG
set DEBUGFLAGS=-g
set LINKER=C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\gcc
set CXXLINKER=C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\g++
set LINKFLAGS=-m64 -Wl,--no-undefined -shared -static shrlibsample.lib -L"C:\Program Files\MATLAB\R2018b\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas -Wl,"C:\Program Files\MATLAB\R2018b/extern/lib/win64/mingw64/mexFunction.def"
set LINKDEBUGFLAGS=-g
set NAME_OUTPUT=-o "%OUTDIR%%MEX_NAME%%MEX_EXT%"
MINGWROOT : C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset
MATLABROOT : C:\Program Files\MATLAB\R2018b
ARCH : win64
SRC : "C:\Users\Javier Ros\Desktop\caca\caca\myAddStructByRef.c";"C:\Program Files\MATLAB\R2018b\extern\version\c_mexapi_version.c"
OBJ : C:\Users\JAVIER~1\AppData\Local\Temp\mex_2295589744729364_9892\myAddStructByRef.obj;C:\Users\JAVIER~1\AppData\Local\Temp\mex_2295589744729364_9892\c_mexapi_version.obj
OBJS : C:\Users\JAVIER~1\AppData\Local\Temp\mex_2295589744729364_9892\myAddStructByRef.obj C:\Users\JAVIER~1\AppData\Local\Temp\mex_2295589744729364_9892\c_mexapi_version.obj
SRCROOT : C:\Users\Javier Ros\Desktop\caca\caca\myAddStructByRef
DEF : C:\Users\JAVIER~1\AppData\Local\Temp\mex_2295589744729364_9892\myAddStructByRef.def
EXP : "myAddStructByRef.exp"
LIB : "myAddStructByRef.lib"
EXE : myAddStructByRef.mexw64
ILK : "myAddStructByRef.ilk"
MANIFEST : "myAddStructByRef.mexw64.manifest"
TEMPNAME : myAddStructByRef
EXEDIR :
EXENAME : myAddStructByRef
OPTIM : -g
LINKOPTIM : -g
CMDLINE1_0 : C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\gcc -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -m64 -DMATLAB_MEX_FILE -I"C:\Program Files\MATLAB\R2018b/extern/include" -I"C:\Program Files\MATLAB\R2018b/simulink/include" -I"C:\Program Files\MATLAB\R2018b/extern\lib\win64\mingw64" -fexceptions -fno-omit-frame-pointer -g "C:\Users\Javier Ros\Desktop\caca\caca\myAddStructByRef.c" -o C:\Users\JAVIER~1\AppData\Local\Temp\mex_2295589744729364_9892\myAddStructByRef.obj
CMDLINE1_1 : C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\gcc -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -m64 -DMATLAB_MEX_FILE -I"C:\Program Files\MATLAB\R2018b/extern/include" -I"C:\Program Files\MATLAB\R2018b/simulink/include" -I"C:\Program Files\MATLAB\R2018b/extern\lib\win64\mingw64" -fexceptions -fno-omit-frame-pointer -g "C:\Program Files\MATLAB\R2018b\extern\version\c_mexapi_version.c" -o C:\Users\JAVIER~1\AppData\Local\Temp\mex_2295589744729364_9892\c_mexapi_version.obj
-------------------------------------------------------------------
Building with 'MinGW64 Compiler (C)'.
C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\gcc -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -m64 -DMATLAB_MEX_FILE -I"C:\Program Files\MATLAB\R2018b/extern/include" -I"C:\Program Files\MATLAB\R2018b/simulink/include" -I"C:\Program Files\MATLAB\R2018b/extern\lib\win64\mingw64" -fexceptions -fno-omit-frame-pointer -g "C:\Users\Javier Ros\Desktop\caca\caca\myAddStructByRef.c" -o C:\Users\JAVIER~1\AppData\Local\Temp\mex_2295589744729364_9892\myAddStructByRef.obj
C:\Users\Javier Ros\Desktop\caca\caca\myAddStructByRef.c: In function 'mexFunction':
C:\Users\Javier Ros\Desktop\caca\caca\myAddStructByRef.c:131:51: warning: passing argument 4 of 'mxCreateStructMatrix_730' from incompatible pointer type [-Wincompatible-pointer-types]
RES_OUT = mxCreateStructMatrix(1, 1, nfields, fnames);
^~~~~~
In file included from C:\Program Files\MATLAB\R2018b/extern/include/mex.h:43:0,
from C:\Users\Javier Ros\Desktop\caca\caca\myAddStructByRef.c:17:
C:\Program Files\MATLAB\R2018b/extern/include/matrix.h:223:30: note: expected 'const char **' but argument is of type 'char **'
#define mxCreateStructMatrix mxCreateStructMatrix_730
^
C:\Program Files\MATLAB\R2018b/extern/include/matrix.h:1396:1: note: in expansion of macro 'mxCreateStructMatrix'
mxCreateStructMatrix(mwSize m, mwSize n, int nfields, const char **fieldnames);
^~~~~~~~~~~~~~~~~~~~
C:\Users\Javier Ros\Desktop\caca\caca\myAddStructByRef.c:143:5: warning: implicit declaration of function 'memcpy' [-Wimplicit-function-declaration]
memcpy(mxGetPr(field), &(st->p2), sizeof(short));
^~~~~~
C:\Users\Javier Ros\Desktop\caca\caca\myAddStructByRef.c:143:5: warning: incompatible implicit declaration of built-in function 'memcpy'
C:\Users\Javier Ros\Desktop\caca\caca\myAddStructByRef.c:143:5: note: include '<string.h>' or provide a declaration of 'memcpy'
C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\gcc -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -m64 -DMATLAB_MEX_FILE -I"C:\Program Files\MATLAB\R2018b/extern/include" -I"C:\Program Files\MATLAB\R2018b/simulink/include" -I"C:\Program Files\MATLAB\R2018b/extern\lib\win64\mingw64" -fexceptions -fno-omit-frame-pointer -g "C:\Program Files\MATLAB\R2018b\extern\version\c_mexapi_version.c" -o C:\Users\JAVIER~1\AppData\Local\Temp\mex_2295589744729364_9892\c_mexapi_version.obj
C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\gcc -m64 -Wl,--no-undefined -shared -static -g -Wl,"C:\Program Files\MATLAB\R2018b/extern/lib/win64/mingw64/exportsmexfileversion.def" C:\Users\JAVIER~1\AppData\Local\Temp\mex_2295589744729364_9892\myAddStructByRef.obj C:\Users\JAVIER~1\AppData\Local\Temp\mex_2295589744729364_9892\c_mexapi_version.obj shrlibsample.lib -L"C:\Program Files\MATLAB\R2018b\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas -o myAddStructByRef.mexw64
Recompile embedded version with '-DMATLAB_MEXCMD_RELEASE=R2017b'
C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\gcc -c -DMATLAB_DEFAULT_RELEASE=R2017b -DUSE_MEX_CMD -m64 -DMATLAB_MEX_FILE -I"C:\Program Files\MATLAB\R2018b/extern/include" -I"C:\Program Files\MATLAB\R2018b/simulink/include" -I"C:\Program Files\MATLAB\R2018b/extern\lib\win64\mingw64" -fexceptions -fno-omit-frame-pointer -g "C:\Program Files\MATLAB\R2018b\extern\version\c_mexapi_version.c" -o C:\Users\JAVIER~1\AppData\Local\Temp\mex_2295589744729364_9892\c_mexapi_version.obj -DMATLAB_MEXCMD_RELEASE=R2017b
C:\ProgramData\MATLAB\SupportPackages\R2018b\3P.instrset\mingw_w64.instrset\bin\gcc -m64 -Wl,--no-undefined -shared -static -g -Wl,"C:\Program Files\MATLAB\R2018b/extern/lib/win64/mingw64/exportsmexfileversion.def" C:\Users\JAVIER~1\AppData\Local\Temp\mex_2295589744729364_9892\myAddStructByRef.obj C:\Users\JAVIER~1\AppData\Local\Temp\mex_2295589744729364_9892\c_mexapi_version.obj shrlibsample.lib -L"C:\Program Files\MATLAB\R2018b\extern\lib\win64\mingw64" -llibmx -llibmex -llibmat -lm -llibmwlapack -llibmwblas -o myAddStructByRef.mexw64
MEX completed successfully.
>> struct.p1 = 4; struct.p2 = 7.3; struct.p3 = -290;
>> [res,st] = myAddStructByRef(struct)
C Struct:
p1: 4.000000
p2: 7
p3: -290
Calculated sum: -279.000000
res =
struct with fields:
p1: 5.5000
p2: 1234
p3: 12345678
st =
-279

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by