Bonjour à tous,
Voilà mon code:
source
header
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 #include "stdafx.h" #include <stdio.h> #define EXPORTING_simplem 1 #include "simplem.h" #ifdef __cplusplus extern "C" { #endif extern mclComponentData __MCC_simplem_component_data; #ifdef __cplusplus } #endif 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) { char szDllPath[_MAX_PATH]; char szDir[_MAX_DIR]; if (GetModuleFileName(hInstance, szDllPath, _MAX_PATH) > 0) { _splitpath(szDllPath, path_to_dll, szDir, NULL, NULL); strcat_s(path_to_dll, szDir); } else 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_simplem_C_API #define LIB_simplem_C_API /* No special import/export declaration */ #endif LIB_simplem_C_API bool MW_CALL_CONV simplemInitializeWithHandlers( mclOutputHandlerFcn error_handler, mclOutputHandlerFcn print_handler ) { if (_mcr_inst != NULL) return true; if (!mclmcrInitialize()) return false; if (!mclInitializeComponentInstance(&_mcr_inst, &__MCC_simplem_component_data, true, NoObjectType, LibTarget, error_handler, print_handler)) return false; return true; } LIB_simplem_C_API bool MW_CALL_CONV simplemInitialize(void) { return simplemInitializeWithHandlers(mclDefaultErrorHandler, mclDefaultPrintHandler); } LIB_simplem_C_API void MW_CALL_CONV simplemTerminate(void) { if (_mcr_inst != NULL) mclTerminateInstance(&_mcr_inst); } LIB_simplem_C_API void MW_CALL_CONV simplemPrintStackTrace(void) { char** stackTrace; int stackDepth = mclGetStackTrace(_mcr_inst, &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_simplem_C_API bool MW_CALL_CONV mlxSimplem(int nlhs, mxArray *plhs[],int nrhs, mxArray *prhs[]) { return mclFeval(_mcr_inst, "simplem", nlhs, plhs, nrhs, prhs); } LIB_simplem_CPP_API void MW_CALL_CONV simplem(int nargout, mwArray& z, const mwArray& x, const mwArray& y) { mclcppMlfFeval(_mcr_inst, "simplem", nargout, 1, 2, &z, &x, &y); }
A la compilation, je reçois l'erreur suivante:
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 #ifndef __simplem_h #define __simplem_h 1 #ifdef MX_COMPAT_32_OFF #ifdef MX_COMPAT_32 #undef MX_COMPAT_32 #endif #else #ifndef MX_COMPAT_32 #define MX_COMPAT_32 #endif #endif #if defined(__cplusplus) && !defined(mclmcr_h) && defined(__linux__) # pragma implementation "mclmcr.h" #endif #include "mclmcr.h" #include "mclcppclass.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_simplem #define PUBLIC_simplem_C_API __global #else #define PUBLIC_simplem_C_API /* No import statement needed. */ #endif #define LIB_simplem_C_API PUBLIC_simplem_C_API #elif defined(_HPUX_SOURCE) #ifdef EXPORTING_simplem #define PUBLIC_simplem_C_API __declspec(dllexport) #else #define PUBLIC_simplem_C_API __declspec(dllimport) #endif #define LIB_simplem_C_API PUBLIC_simplem_C_API #else #define LIB_simplem_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_simplem_C_API #define LIB_simplem_C_API /* No special import/export declaration */ #endif extern LIB_simplem_C_API bool MW_CALL_CONV simplemInitializeWithHandlers(mclOutputHandlerFcn error_handler, mclOutputHandlerFcn print_handler); extern LIB_simplem_C_API bool MW_CALL_CONV simplemInitialize(void); extern LIB_simplem_C_API void MW_CALL_CONV simplemTerminate(void); extern LIB_simplem_C_API void MW_CALL_CONV simplemPrintStackTrace(void); extern LIB_simplem_C_API bool MW_CALL_CONV mlxSimplem(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[]); #ifdef __cplusplus } #endif #ifdef __cplusplus /* On Windows, use __declspec to control the exported API */ #if defined(_MSC_VER) || defined(__BORLANDC__) #ifdef EXPORTING_simplem #define PUBLIC_simplem_CPP_API __declspec(dllexport) #else #define PUBLIC_simplem_CPP_API __declspec(dllimport) #endif #define LIB_simplem_CPP_API PUBLIC_simplem_CPP_API #else #if !defined(LIB_simplem_CPP_API) #if defined(LIB_simplem_C_API) #define LIB_simplem_CPP_API LIB_simplem_C_API #else #define LIB_simplem_CPP_API /* empty! */ #endif #endif #endif extern LIB_simplem_CPP_API void MW_CALL_CONV simplem(int nargout, mwArray& z , const mwArray& x , const mwArray& y); #endif #endif
Le code est en fait un fichier wrapper pour la fonction matlab simplem (bête fonction de test), donc évidemment il est assez complexe et pas très lisible.simplemvs\simplem.cpp(146) : error C2491: 'simplem'*: définition de fonction dllimport non autorisée
Comment résoudre ce problème?
Merci beaucoup!
Partager