×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

mex link error when compiling s-function c++

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close