problem with building a simulink model with two s-functions written in C language

8 visualizaciones (últimos 30 días)
Hi all, I have a problem with building a Simulink model for Real-time aplication. I try to build a mdl with two S-functions written in C. I use same header files in both S-functions. I have biult the C files with "mex MPCtest1.c MPCtest2.c" (these are very simple test S-functions whih I created to try resolving the problem). Here is the message that Matlab produces:
MPCtest2.obj : error LNK2005: __ssSetInputPortMatrixDimensions already defined in MPCtest1.obj
MPCtest2.obj : error LNK2005: __ssSetOutputPortMatrixDimensions already defined in MPCtest1.obj
MPCtest2.obj : error LNK2005: __ssSetInputPortVectorDimension already defined in MPCtest1.obj
MPCtest2.obj : error LNK2005: __ssSetOutputPortVectorDimension already defined in MPCtest1.obj
MPCtest2.obj : error LNK2005: _ssIsRunTimeParamTunable already defined in MPCtest1.obj
MPCtest2.obj : error LNK2005: _ssGetSFuncBlockHandle already defined in MPCtest1.obj
MPCtest2.obj : error LNK2005: __ssGetCurrentInputPortWidth already defined in MPCtest1.obj
MPCtest2.obj : error LNK2005: __ssGetCurrentOutputPortWidth already defined in MPCtest1.obj
MPCtest2.obj : error LNK2005: _ssWarning already defined in MPCtest1.obj
MPCtest2.obj : error LNK2005: _ssGetDTypeIdFromMxArray already defined in MPCtest1.obj
MPCtest2.obj : error LNK2005: _ssWriteRTWStr already defined in MPCtest1.obj
MPCtest2.obj : error LNK2005: _ssWriteRTWNameValuePair already defined in MPCtest1.obj
MPCtest2.obj : error LNK2005: _ssWriteRTWParameters already defined in MPCtest1.obj
MPCtest2.obj : error LNK2005: _ssWriteRTWParamSettings already defined in MPCtest1.obj
MPCtest2.obj : error LNK2005: _ssWriteRTWWorkVect already defined in MPCtest1.obj
MPCtest2.obj : error LNK2005: _mexFunction already defined in MPCtest1.obj
MPCtest2.obj : error LNK2005: _ssWriteRTWMxVectParam already defined in MPCtest1.obj
MPCtest2.obj : error LNK2005: _ssWriteRTWMx2dMatParam already defined in MPCtest1.obj
MPCtest2.obj : error LNK2005: _DYNAMIC_DIMENSION_DEF already defined in MPCtest1.obj
MPCtest2.obj : error LNK2005: _DYNAMIC_DIMENSION already defined in MPCtest1.obj
It seams that the reason is simstruc.h header!??! I cannot understand why it is happening.
It would be great if someone could help me.
Thank you!!!

Respuesta aceptada

Kaustubha Govind
Kaustubha Govind el 1 de Sept. de 2011
You need to compile them separately - they need to be two separate binaries:
mex MPCtest1.c
mex MPCtest2.c

Más respuestas (1)

Sevil Ahmed
Sevil Ahmed el 1 de Sept. de 2011
Hi Kaustubha Govind, thank you for you answer. I tried with separate compiled files. This time I have a new problem - caused by my header file I think.
I compiled
mex MPCtest1.c MYheader.c mex MPCtest2.c MYheader.c
I think it is the way to add own headers in S-functions (maybe I'm wrong:)) I have MYheader.h file also.
Error message this time is:
### Linking ... C:\PROGRA~2\MATLAB\R2008b\sys\perl\win32\bin\perl C:\PROGRA~2\MATLAB\R2008b\rtw\c\tools\mkvc_lnk.pl OPTIM5.lnk OPTIM5.obj OPTIM5_data.obj rtGetInf.obj rtGetNaN.obj rt_logging.obj rt_matrx.obj rt_nonfinite.obj rt_pow_snf.obj rt_printf.obj grt_main.obj rt_sim.obj ode3.obj MPCtest2.obj MPCtest1.obj link /RELEASE /INCREMENTAL:NO /NOLOGO -subsystem:console,5.0 kernel32.lib ws2_32.lib mswsock.lib advapi32.lib libcpmt.lib @OPTIM5.lnk @OPTIM5_ref.rsp -out:..\OPTIM5.exe MPCtest2.obj : error LNK2019: unresolved external symbol _func1 referenced in function _mdlUpdate MPCtest1.obj : error LNK2001: unresolved external symbol _func1 ..\OPTIM5.exe : fatal error LNK1120: 1 unresolved externals NMAKE : fatal error U1077: '"c:\program files (x86)\microsoft visual studio 9.0\VC\BIN\link.EXE"' : return code '0x460' Stop.
where func1 is the function from MYheader. Everything is simplified in order to solve the problem:) but I still cannot find the solution
//MYheader.h
#ifndef MYheader_H
#define MYheader_H
int func1(int a);
#endif
//MYheader.c
#include "MYheader.h"
int func1(int a){
int k;
return k = a*20;
}
I cannot uderstand why mex passes without any errors if the way I compile the main file and the header is wrong!?

Categorías

Más información sobre Debugging and Analysis en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by