mex link error when compiling s-function c++
mex link error when compiling s-function c++
(OP)
I have gotten my s-function to compile in Visual Studio .NET 2003 but when I run the mex command on it in MATLAB to create the dll for the s-function it gives me this error when attempting to link:
--> "link /out:"regICPMAT.dll" /debug /dll /export:mexFunction /MAP /LIBPATH:"C:\MATLAB\extern\lib\win32\microsoft\msvc71" libmx.lib libmex.lib libmat.lib /implib:_lib9555.x @9555_tmp.rsp "
Microsoft (R) Incremental Linker Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.
regICPMAT.obj
Creating library _lib9555.x and object _lib9555.exp
regICPMAT.obj : error LNK2019: unresolved external symbol "void __cdecl registration(double *,int,double *,int,double *,int,double * const)" (?registration@@YAXPANH0H0HQAN@Z) referenced in function _mdlOutputs
regICPMAT.dll : fatal error LNK1120: 1 unresolved externals
C:\MATLAB\BIN\WIN32\MEX.PL: Error: Link of 'regICPMAT.dll' failed.
Can anyone suggest why this is happening when it calls the registration function (registration is a seperate c++ class code that I have written but I included it as a header so i don't understand the problem).
HERE IS MY S_FUNCTION:
#define S_FUNCTION_LEVEL 2
#define MATLAB_MEX_FILE
#define S_FUNCTION_NAME regICPMAT
#include "mex.h"
#include "registration.h"
#ifdef __cplusplus
extern "C" { // use the C fcn-call standard for all functions
#endif // defined within this scope
#include "simstruc.h"
static void mdlInitializeSizes(SimStruct *S)
{
/* See sfuntmpl_doc.c for more details on the macros below */
ssSetNumSFcnParams(S, 0); /* Number of expected parameters */
if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/* Return if number of expected != number of actual parameters */
return;
}
ssSetNumContStates(S, 0);
ssSetNumDiscStates(S, 0);
if (!ssSetNumInputPorts(S, 6)) return;
ssSetInputPortDataType( S, 0, SS_DOUBLE);
ssSetInputPortWidth(S, 0, DYNAMICALLY_SIZED);
ssSetInputPortDataType(S, 1, SS_INT32);
ssSetInputPortWidth(S, 1, 1);
ssSetInputPortDataType( S, 2, SS_DOUBLE);
ssSetInputPortWidth(S, 2, DYNAMICALLY_SIZED);
ssSetInputPortDataType(S, 3, SS_INT32);
ssSetInputPortWidth(S, 3, 1);
ssSetInputPortDataType( S, 4, SS_DOUBLE);
ssSetInputPortWidth(S, 4, DYNAMICALLY_SIZED);
ssSetInputPortDataType(S, 5, SS_INT32);
ssSetInputPortWidth(S, 5, 1);
ssSetInputPortRequiredContiguous(S, 0, true); /*direct input signal access*/
ssSetInputPortRequiredContiguous(S, 1, true);
ssSetInputPortRequiredContiguous(S, 2, true);
ssSetInputPortRequiredContiguous(S, 3, true);
ssSetInputPortRequiredContiguous(S, 4, true);
ssSetInputPortRequiredContiguous(S, 5, true);
ssSetInputPortRequiredContiguous(S, 6, true);
//i think this should be zero for all since they do not directly enter into output
ssSetInputPortDirectFeedThrough(S, 0, 0);
ssSetInputPortDirectFeedThrough(S, 1, 0);
ssSetInputPortDirectFeedThrough(S, 2, 0);
ssSetInputPortDirectFeedThrough(S, 3, 0);
ssSetInputPortDirectFeedThrough(S, 4, 0);
ssSetInputPortDirectFeedThrough(S, 5, 0);
if (!ssSetNumOutputPorts(S, 1)) return;
ssSetOutputPortMatrixDimensions(S, 0, 4, 4);
ssSetNumSampleTimes(S, 1);
ssSetNumRWork(S, 0);
ssSetNumIWork(S, 0);
ssSetNumPWork(S, 0);
ssSetNumModes(S, 0);
ssSetNumNonsampledZCs(S, 0);
ssSetOptions(S, 0);
}
static void mdlInitializeSampleTimes(SimStruct *S)
{
//what kind of sample time should be used
//ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME);
ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME);
ssSetOffsetTime(S, 0, 0.0);
}
#define MDL_INITIALIZE_CONDITIONS /* Change to #undef to remove function */
#if defined(MDL_INITIALIZE_CONDITIONS)
static void mdlInitializeConditions(SimStruct *S)
{
}
#endif /* MDL_INITIALIZE_CONDITIONS */
#define MDL_START /* Change to #undef to remove function */
#if defined(MDL_START)
static void mdlStart(SimStruct *S)
{
}
#endif /* MDL_START */
static void mdlOutputs(SimStruct *S, int_T tid)
{
//set input from input ports
double *in1 = (double*) ssGetInputPortSignal(S,0);
int in2 = (int) ssGetInputPortSignal(S,1);
double *in3 = (double*) ssGetInputPortSignal(S,2);
int in4 = (int) ssGetInputPortSignal(S,3);
double *in5 = (double*) ssGetInputPortSignal(S,4);
int in6 = (int) ssGetInputPortSignal(S,5);
//set output port
double *output = (double*)ssGetOutputPortSignal(S,0); //this is fine
double matrix[16];
registration(in1,in2,in3,in4,in5,in6,matrix);
output = matrix;
}
#define MDL_UPDATE /* Change to #undef to remove function */
#if defined(MDL_UPDATE)
static void mdlUpdate(SimStruct *S, int_T tid)
{
}
#endif /* MDL_UPDATE */
#define MDL_DERIVATIVES /* Change to #undef to remove function */
#if defined(MDL_DERIVATIVES)
static void mdlDerivatives(SimStruct *S)
{
}
#endif /* MDL_DERIVATIVES */
static void mdlTerminate(SimStruct *S)
{
}
#ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? */
#include "simulink.c" /* MEX-file interface mechanism */
#else
#include "cg_sfun.h" /* Code generation registration function */
#endif
#ifdef __cplusplus
} // end of extern "C" scope
#endif
--> "link /out:"regICPMAT.dll" /debug /dll /export:mexFunction /MAP /LIBPATH:"C:\MATLAB\extern\lib\win32\microsoft\msvc71" libmx.lib libmex.lib libmat.lib /implib:_lib9555.x @9555_tmp.rsp "
Microsoft (R) Incremental Linker Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.
regICPMAT.obj
Creating library _lib9555.x and object _lib9555.exp
regICPMAT.obj : error LNK2019: unresolved external symbol "void __cdecl registration(double *,int,double *,int,double *,int,double * const)" (?registration@@YAXPANH0H0HQAN@Z) referenced in function _mdlOutputs
regICPMAT.dll : fatal error LNK1120: 1 unresolved externals
C:\MATLAB\BIN\WIN32\MEX.PL: Error: Link of 'regICPMAT.dll' failed.
Can anyone suggest why this is happening when it calls the registration function (registration is a seperate c++ class code that I have written but I included it as a header so i don't understand the problem).
HERE IS MY S_FUNCTION:
#define S_FUNCTION_LEVEL 2
#define MATLAB_MEX_FILE
#define S_FUNCTION_NAME regICPMAT
#include "mex.h"
#include "registration.h"
#ifdef __cplusplus
extern "C" { // use the C fcn-call standard for all functions
#endif // defined within this scope
#include "simstruc.h"
static void mdlInitializeSizes(SimStruct *S)
{
/* See sfuntmpl_doc.c for more details on the macros below */
ssSetNumSFcnParams(S, 0); /* Number of expected parameters */
if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) {
/* Return if number of expected != number of actual parameters */
return;
}
ssSetNumContStates(S, 0);
ssSetNumDiscStates(S, 0);
if (!ssSetNumInputPorts(S, 6)) return;
ssSetInputPortDataType( S, 0, SS_DOUBLE);
ssSetInputPortWidth(S, 0, DYNAMICALLY_SIZED);
ssSetInputPortDataType(S, 1, SS_INT32);
ssSetInputPortWidth(S, 1, 1);
ssSetInputPortDataType( S, 2, SS_DOUBLE);
ssSetInputPortWidth(S, 2, DYNAMICALLY_SIZED);
ssSetInputPortDataType(S, 3, SS_INT32);
ssSetInputPortWidth(S, 3, 1);
ssSetInputPortDataType( S, 4, SS_DOUBLE);
ssSetInputPortWidth(S, 4, DYNAMICALLY_SIZED);
ssSetInputPortDataType(S, 5, SS_INT32);
ssSetInputPortWidth(S, 5, 1);
ssSetInputPortRequiredContiguous(S, 0, true); /*direct input signal access*/
ssSetInputPortRequiredContiguous(S, 1, true);
ssSetInputPortRequiredContiguous(S, 2, true);
ssSetInputPortRequiredContiguous(S, 3, true);
ssSetInputPortRequiredContiguous(S, 4, true);
ssSetInputPortRequiredContiguous(S, 5, true);
ssSetInputPortRequiredContiguous(S, 6, true);
//i think this should be zero for all since they do not directly enter into output
ssSetInputPortDirectFeedThrough(S, 0, 0);
ssSetInputPortDirectFeedThrough(S, 1, 0);
ssSetInputPortDirectFeedThrough(S, 2, 0);
ssSetInputPortDirectFeedThrough(S, 3, 0);
ssSetInputPortDirectFeedThrough(S, 4, 0);
ssSetInputPortDirectFeedThrough(S, 5, 0);
if (!ssSetNumOutputPorts(S, 1)) return;
ssSetOutputPortMatrixDimensions(S, 0, 4, 4);
ssSetNumSampleTimes(S, 1);
ssSetNumRWork(S, 0);
ssSetNumIWork(S, 0);
ssSetNumPWork(S, 0);
ssSetNumModes(S, 0);
ssSetNumNonsampledZCs(S, 0);
ssSetOptions(S, 0);
}
static void mdlInitializeSampleTimes(SimStruct *S)
{
//what kind of sample time should be used
//ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME);
ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME);
ssSetOffsetTime(S, 0, 0.0);
}
#define MDL_INITIALIZE_CONDITIONS /* Change to #undef to remove function */
#if defined(MDL_INITIALIZE_CONDITIONS)
static void mdlInitializeConditions(SimStruct *S)
{
}
#endif /* MDL_INITIALIZE_CONDITIONS */
#define MDL_START /* Change to #undef to remove function */
#if defined(MDL_START)
static void mdlStart(SimStruct *S)
{
}
#endif /* MDL_START */
static void mdlOutputs(SimStruct *S, int_T tid)
{
//set input from input ports
double *in1 = (double*) ssGetInputPortSignal(S,0);
int in2 = (int) ssGetInputPortSignal(S,1);
double *in3 = (double*) ssGetInputPortSignal(S,2);
int in4 = (int) ssGetInputPortSignal(S,3);
double *in5 = (double*) ssGetInputPortSignal(S,4);
int in6 = (int) ssGetInputPortSignal(S,5);
//set output port
double *output = (double*)ssGetOutputPortSignal(S,0); //this is fine
double matrix[16];
registration(in1,in2,in3,in4,in5,in6,matrix);
output = matrix;
}
#define MDL_UPDATE /* Change to #undef to remove function */
#if defined(MDL_UPDATE)
static void mdlUpdate(SimStruct *S, int_T tid)
{
}
#endif /* MDL_UPDATE */
#define MDL_DERIVATIVES /* Change to #undef to remove function */
#if defined(MDL_DERIVATIVES)
static void mdlDerivatives(SimStruct *S)
{
}
#endif /* MDL_DERIVATIVES */
static void mdlTerminate(SimStruct *S)
{
}
#ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? */
#include "simulink.c" /* MEX-file interface mechanism */
#else
#include "cg_sfun.h" /* Code generation registration function */
#endif
#ifdef __cplusplus
} // end of extern "C" scope
#endif