'rtwinext': undefined symbol "__imp__Z1​3TT_Initia​lizev" Error loading real-time executable Error occurred while executing External Mode MEX-file motive 1.5 API C-MEX S-Function

1 visualizzazione (ultimi 30 giorni)
I wrote custom C-mex s-function to get data from external software using API Library. the s-function is working well in Normal mode but when i switch to external mode using Real-Time Windows Target it show the following error.
also i"m using C++ compiler because the API Library is written in C++.
Error occurred while executing External Mode MEX-file 'rtwinext': Error loading real-time executable: undefined symbol "__imp__Z13TT_Initializev"
I'm trying to get position data from Natural-Point's optitrack cameras using Motive 1.5 API and to control a quad-copter in real-time Simulink
my project is avilable in GitHub: https://github.com/orhirshfeld/Motive-S-function.git
my s-function is the following:
#define S_FUNCTION_NAME Get_Data_From_Motive_API_v2_realtime #define S_FUNCTION_LEVEL 2
#include "simstruc.h" //for s-function building
//#include "mex.h" //for mexing
//#include stdio.h //for printf function //#include windows.h //for sleep function //#include math.h //for isnan function
#include "NPTrackingTools.h" //for motive API
/*================* * Build checking ================*/
/* Function: mdlInitializeSizes =============================================== * Abstract: * Setup sizes of the various vectors. / static void mdlInitializeSizes(SimStruct *S) { ssSetNumSFcnParams(S, 0); if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S)) { return; / Parameter mismatch will be reported by Simulink */ }
if (!ssSetNumInputPorts(S, 1)) return;
ssSetInputPortWidth(S, 0, 1);
ssSetInputPortDataType(S, 0, DYNAMICALLY_TYPED );
ssSetInputPortDirectFeedThrough(S, 0, 1);
if (!ssSetNumOutputPorts(S,8)) return; // insert here to change number of output ports
ssSetOutputPortWidth(S, 0, 1);
ssSetOutputPortDataType(S, 0, DYNAMICALLY_TYPED );
ssSetOutputPortWidth(S, 1, 1);
ssSetOutputPortDataType(S, 1, DYNAMICALLY_TYPED );
ssSetOutputPortWidth(S, 2, 1);
ssSetOutputPortDataType(S, 2, DYNAMICALLY_TYPED );
ssSetOutputPortWidth(S, 3, 1);
ssSetOutputPortDataType(S, 3, DYNAMICALLY_TYPED );
ssSetOutputPortWidth(S, 4, 1);
ssSetOutputPortDataType(S, 4, DYNAMICALLY_TYPED );
ssSetOutputPortWidth(S, 5, 1);
ssSetOutputPortDataType(S, 5, DYNAMICALLY_TYPED );
ssSetOutputPortWidth(S, 6, 1);
ssSetOutputPortDataType(S, 6, DYNAMICALLY_TYPED );
ssSetOutputPortWidth(S, 7, 1);
ssSetOutputPortDataType(S, 7, DYNAMICALLY_TYPED );
ssSetNumSampleTimes(S, 1);
/* specify the sim state compliance to be same as a built-in block */
ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE);
ssSetOptions(S,
SS_OPTION_CALL_TERMINATE_ON_EXIT |
SS_OPTION_EXCEPTION_FREE_CODE);
// SS_OPTION_WORKS_WITH_CODE_REUSE and SS_OPTION_USE_TLC_WITH_ACCELERATOR were romoved
// set inner value for old_timestamp to messure delta time btween ithreations
ssSetNumDWork(S, 1);
ssSetDWorkWidth(S, 0, 1);
ssSetDWorkDataType(S, 0, SS_DOUBLE);
}
/* Function: mdlInitializeSampleTimes ========================================= * Abstract: * Specifiy that we inherit our sample time from the driving block. */ static void mdlInitializeSampleTimes(SimStruct *S) { ssSetSampleTime(S, 0, INHERITED_SAMPLE_TIME); ssSetOffsetTime(S, 0, 0.0); ssSetModelReferenceSampleTimeDefaultInheritance(S); }
#define MDL_START void mdlStart(SimStruct S) { int ret1; const char project_file_name[130] = "c:\\Users\\sasson\\onedrive\\work control lab aero summer 2014 technion\\C_code\\Motive-S-function\\MOTIVE15.ttp"; double *TimeStamp_old = (double) ssGetDWork(S,0);
TimeStamp_old[0]=0;
ret1=TT_Initialize();
//Sleep(100); not avilable in real-time
ret1=TT_LoadProject(project_file_name);
//Sleep(1000); notavilable in real-time
}
/* Function: mdlOutputs ======================================================= / static void mdlOutputs(SimStruct *S, int_T tid) { InputRealPtrsType uPtrs = ssGetInputPortRealSignalPtrs(S,0); real_T *X = ssGetOutputPortRealSignal(S,0); real_T *Y = ssGetOutputPortRealSignal(S,1); real_T *Z = ssGetOutputPortRealSignal(S,2); real_T *Yaw = ssGetOutputPortRealSignal(S,3); real_T *Pitch = ssGetOutputPortRealSignal(S,4); real_T *Roll = ssGetOutputPortRealSignal(S,5); real_T *TimeStamp = ssGetOutputPortRealSignal(S,6); real_T *DeltaTime = ssGetOutputPortRealSignal(S,7); double *TimeStamp_old = (double) ssGetDWork(S,0);
float x1=999, y1=999, z1=999, qx1=999, qy1=999, qz1=999, qw1=999, yaw1=999, pitch1=999, roll1=999;
double TimeStamp1=0;
double DeltaTime1=0;
int_T width = ssGetOutputPortWidth(S,0);
int ret2;
int ID_num;
ID_num=(int) *uPtrs[0]; //obtain input
ret2=TT_UpdateSingleFrame();
TT_TrackableLocation(ID_num, &x1, &y1, &z1, &qx1, &qy1, &qz1, &qw1, &yaw1, &pitch1, &roll1);
TimeStamp1=TT_FrameTimeStamp();
DeltaTime1=TimeStamp1-TimeStamp_old[0];
TimeStamp_old[0]=TimeStamp1;
*X=(real_T) x1;
*Y=(real_T) y1;
*Z=(real_T) z1;
*Yaw=(real_T) yaw1;
*Pitch=(real_T) pitch1;
*Roll=(real_T) roll1;
*TimeStamp=(real_T) TimeStamp1;
*DeltaTime=(real_T) DeltaTime1;
// Sleep(100); not avilable in real-time
}
/* Function: mdlTerminate ===================================================== * Abstract: * No termination needed, but we are required to have this routine. */ static void mdlTerminate(SimStruct *S) { int_T ret3;
// ret4=TT_FinalCleanup(); //create error ret3=TT_Shutdown();
}
#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
Thank you Or Hirshfeld אור הירשפלד

Risposta accettata

Or Hirshfeld
Or Hirshfeld il 28 Mag 2015
Modificato: Or Hirshfeld il 28 Mag 2015
I got the following answer from Matlab support:
Or Hirshfeld אור הירשפלד
  2 Commenti
David St-Onge
David St-Onge il 29 Mag 2015
ok, but what if you use #pragma comment with static .lib library? In my understanding it should work, but I'm having the same issue as you....
Christine
Christine il 10 Giu 2015
I'm facing a similar issue. Could you please report the answer from MATLAB support. It isn't quite legible. Thank you.

Accedi per commentare.

Più risposte (1)

Anthony Poulin
Anthony Poulin il 21 Mag 2015
Hello,
I think that I have encountered a similar problem and it comes from "mex.h" (which is a Matlab API and if you simulate in external mode it can occur troubleshot).
Can you try to suppress the inclusion of mex.h (and relevant functions) on your code?
  3 Commenti
Anthony Poulin
Anthony Poulin il 22 Mag 2015
Can you tell me when did you get this error?
When trying to compile your s-function in a mex file? Or you succeed to do it but it happens when you launch your simulation?
Or Hirshfeld
Or Hirshfeld il 28 Mag 2015
Modificato: Or Hirshfeld il 28 Mag 2015
I get the error while trying to run it (press play button)
when i compile is all fine and it working when i run it in normal mode
The answer that i got from matlab support is:
but i have Lib file as well as dll file, I don't know if it consider source code or binary file becuse i know lib file is cross-platfrom
also i saw something in the header file about some option to load the library as dynamic or static.
//== DLL EXPORT/IMPORT PREPROCESSOR DEFINES ==========================================-----
#ifdef NPTRACKINGTOOLS_EXPORTS
#define TTAPI __declspec(dllexport)
#else
#ifndef STATIC_TT_LINK
#define TTAPI __declspec(dllimport)
#else
#define TTAPI
#endif
#endif
i attached the dll/lib header file as txt file
another thing to note is that my API connect to software, not hardware

Accedi per commentare.

Categorie

Scopri di più su Simulink Coder in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by