Bonjour,

Je travaille avec MATLAB R2011b (avec la version 4.16 du Compiler).
Je veux transformer une fonction MATLAB en langage C/C++, et j'ai cru comprendre qu'il fallait utiliser la commande mcc.

Pour me "faire la main" j'ai testé cela sur une fonction des plus simples :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
function res=somme(a,b)
res=a+b;
end
Quelqu'un peut-il m'expliquer pourquoi, lorsque je compile cette fonction avec
Code : Sélectionner tout - Visualiser dans une fenêtre à part
mcc -l somme.m -d D:\conversion_simple
j'obtiens des fichiers .c et .h aussi compliqués ?

somme.h


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 * MATLAB Compiler: 4.16 (R2011b)
 * Date: Mon Jun 04 17:54:05 2012
 * Arguments: "-B" "macro_default" "-l" "somme.m" "-d" "D:\conversion_simple" 
 */
 
#ifndef __somme_h
#define __somme_h 1
 
#if defined(__cplusplus) && !defined(mclmcrrt_h) && defined(__linux__)
#  pragma implementation "mclmcrrt.h"
#endif
#include "mclmcrrt.h"
#ifdef __cplusplus
extern "C" {
#endif
 
#if defined(__SUNPRO_CC)
/* Solaris shared libraries use __global, rather than mapfiles
 * to define the API exported from a shared library. __global is
 * only necessary when building the library -- files including
 * this header file to use the library do not need the __global
 * declaration; hence the EXPORTING_<library> logic.
 */
 
#ifdef EXPORTING_somme
#define PUBLIC_somme_C_API __global
#else
#define PUBLIC_somme_C_API /* No import statement needed. */
#endif
 
#define LIB_somme_C_API PUBLIC_somme_C_API
 
#elif defined(_HPUX_SOURCE)
 
#ifdef EXPORTING_somme
#define PUBLIC_somme_C_API __declspec(dllexport)
#else
#define PUBLIC_somme_C_API __declspec(dllimport)
#endif
 
#define LIB_somme_C_API PUBLIC_somme_C_API
 
 
#else
 
#define LIB_somme_C_API
 
#endif
 
/* This symbol is defined in shared libraries. Define it here
 * (to nothing) in case this isn't a shared library. 
 */
#ifndef LIB_somme_C_API 
#define LIB_somme_C_API /* No special import/export declaration */
#endif
 
extern LIB_somme_C_API 
bool MW_CALL_CONV sommeInitializeWithHandlers(
       mclOutputHandlerFcn error_handler, 
       mclOutputHandlerFcn print_handler);
 
extern LIB_somme_C_API 
bool MW_CALL_CONV sommeInitialize(void);
 
extern LIB_somme_C_API 
void MW_CALL_CONV sommeTerminate(void);
 
 
 
extern LIB_somme_C_API 
void MW_CALL_CONV sommePrintStackTrace(void);
 
extern LIB_somme_C_API 
bool MW_CALL_CONV mlxSomme(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[]);
 
extern LIB_somme_C_API 
long MW_CALL_CONV sommeGetMcrID();
 
 
 
extern LIB_somme_C_API bool MW_CALL_CONV mlfSomme(int nargout, mxArray** res, mxArray* a, mxArray* b);
 
#ifdef __cplusplus
}
#endif
#endif

somme.c

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
 * MATLAB Compiler: 4.16 (R2011b)
 * Date: Mon Jun 04 17:54:05 2012
 * Arguments: "-B" "macro_default" "-l" "somme.m" "-d" "D:\conversion_simple" 
 */
 
#include <stdio.h>
#define EXPORTING_somme 1
#include "somme.h"
 
static HMCRINSTANCE _mcr_inst = NULL;
 
 
#if defined( _MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__LCC__)
#ifdef __LCC__
#undef EXTERN_C
#endif
#include <windows.h>
 
static char path_to_dll[_MAX_PATH];
 
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, void *pv)
{
    if (dwReason == DLL_PROCESS_ATTACH)
    {
        if (GetModuleFileName(hInstance, path_to_dll, _MAX_PATH) == 0)
            return FALSE;
    }
    else if (dwReason == DLL_PROCESS_DETACH)
    {
    }
    return TRUE;
}
#endif
#ifdef __cplusplus
extern "C" {
#endif
 
static int mclDefaultPrintHandler(const char *s)
{
  return mclWrite(1 /* stdout */, s, sizeof(char)*strlen(s));
}
 
#ifdef __cplusplus
} /* End extern "C" block */
#endif
 
#ifdef __cplusplus
extern "C" {
#endif
 
static int mclDefaultErrorHandler(const char *s)
{
  int written = 0;
  size_t len = 0;
  len = strlen(s);
  written = mclWrite(2 /* stderr */, s, sizeof(char)*len);
  if (len > 0 && s[ len-1 ] != '\n')
    written += mclWrite(2 /* stderr */, "\n", sizeof(char));
  return written;
}
 
#ifdef __cplusplus
} /* End extern "C" block */
#endif
 
/* This symbol is defined in shared libraries. Define it here
 * (to nothing) in case this isn't a shared library. 
 */
#ifndef LIB_somme_C_API
#define LIB_somme_C_API /* No special import/export declaration */
#endif
 
LIB_somme_C_API 
bool MW_CALL_CONV sommeInitializeWithHandlers(
    mclOutputHandlerFcn error_handler,
    mclOutputHandlerFcn print_handler)
{
    int bResult = 0;
  if (_mcr_inst != NULL)
    return true;
  if (!mclmcrInitialize())
    return false;
  if (!GetModuleFileName(GetModuleHandle("somme"), path_to_dll, _MAX_PATH))
    return false;
    {
        mclCtfStream ctfStream = 
            mclGetEmbeddedCtfStream(path_to_dll, 
                                    38504);
        if (ctfStream) {
            bResult = mclInitializeComponentInstanceEmbedded(   &_mcr_inst,
                                                                error_handler, 
                                                                print_handler,
                                                                ctfStream, 
                                                                38504);
            mclDestroyStream(ctfStream);
        } else {
            bResult = 0;
        }
    }  
    if (!bResult)
    return false;
  return true;
}
 
LIB_somme_C_API 
bool MW_CALL_CONV sommeInitialize(void)
{
  return sommeInitializeWithHandlers(mclDefaultErrorHandler, mclDefaultPrintHandler);
}
 
LIB_somme_C_API 
void MW_CALL_CONV sommeTerminate(void)
{
  if (_mcr_inst != NULL)
    mclTerminateInstance(&_mcr_inst);
}
 
LIB_somme_C_API 
long MW_CALL_CONV sommeGetMcrID() 
{
  return mclGetID(_mcr_inst);
}
 
LIB_somme_C_API 
void MW_CALL_CONV sommePrintStackTrace(void) 
{
  char** stackTrace;
  int stackDepth = mclGetStackTrace(&stackTrace);
  int i;
  for(i=0; i<stackDepth; i++)
  {
    mclWrite(2 /* stderr */, stackTrace[i], sizeof(char)*strlen(stackTrace[i]));
    mclWrite(2 /* stderr */, "\n", sizeof(char)*strlen("\n"));
  }
  mclFreeStackTrace(&stackTrace, stackDepth);
}
 
 
LIB_somme_C_API 
bool MW_CALL_CONV mlxSomme(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[])
{
  return mclFeval(_mcr_inst, "somme", nlhs, plhs, nrhs, prhs);
}
 
LIB_somme_C_API 
bool MW_CALL_CONV mlfSomme(int nargout, mxArray** res, mxArray* a, mxArray* b)
{
  return mclMlfFeval(_mcr_inst, "somme", nargout, 1, 2, res, a, b);
}


Merci pour votre aide !