How can I compile C++ codes using DLL files created in Matlab in the IDE Code::Blocks?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
*Steps I have taken before compiling:
- Created a Matlab C-S Function Project
- Added the .dll file (libtest.dll) and all other associated files (libtest.lib, libtest.h,etc) created in Matlab previously to the project
- Added a C++ file, mcctest.cpp, I created to use a function in the .dll file above
- Made sure all the library files from Matlab's "extern/lib" and "sys/lcc/lib" are linked in COde::Blocks
- Made sure to add the paths "extern/include" and "sys/lcc/include" in the Code::Blocks compiler settings
- Set up Code::Blocks to work with Matlab's LCC compiler*
When I finally run mcctest.cpp:
#include <iostream>
#include "libtest.h"
using namespace std;
int main() {
// Initialize the MATLAB Compiler Runtime global state
if (!mclInitializeApplication(NULL,0))
{
std::cerr << "Could not initialize the application properly."
<< std::endl;
return -1;
}
// Initialize the libtest library created in Matlab
if( !libtestInitialize() )
{
std::cerr << "Could not initialize the library properly."
<< std::endl;
return -1;
}
double dat[1] = {4};
mwArray x1(1,1,mxDOUBLE_CLASS);
x1.SetData(dat,1);
mwArray x0;
int out = 1;
funcx(out,x0,x1);
//cout << a[];
}
These are the error's I get:
mcctest.cpp: C:\Program Files\MATLAB\R2011a\extern\include\mclmcr.h|1251|syntax error; found `int32_t' expecting `}'|
mcctest.cpp: C:\Program Files\MATLAB\R2011a\extern\include\mclmcr.h|1251|skipping `int32_t' `buffLen'|
mcctest.cpp: C:\Program Files\MATLAB\R2011a\extern\include\mclmcr.h|1252|unrecognized declaration|
mcctest.cpp: C:\Program Files\MATLAB\R2011a\extern\include\mclmcr.h|1255|syntax error; found `ptr' expecting `)'|
mcctest.cpp: C:\Program Files\MATLAB\R2011a\extern\include\mclmcr.h|1255|skipping `ptr'|
mcctest.cpp: C:\Program Files\MATLAB\R2011a\extern\include\mclmcr.h|1255|extraneous old-style parameter list|
mcctest.cpp: C:\Program Files\MATLAB\R2011a\extern\include\mclmcr.h|1258|syntax error; found `*' expecting `)'|
mcctest.cpp: C:\Program Files\MATLAB\R2011a\extern\include\mclmcr.h|1258|skipping `*' `ptr'|
mcctest.cpp: C:\Program Files\MATLAB\R2011a\extern\include\mclmcr.h|1258|extraneous old-style parameter list|
mcctest.cpp: C:\Program Files\MATLAB\R2011a\extern\include\mclmcr.h|1261|syntax error; found `ptr' expecting `)'|
mcctest.cpp: C:\Program Files\MATLAB\R2011a\extern\include\mclmcr.h|1261|skipping `ptr'|
mcctest.cpp: C:\Program Files\MATLAB\R2011a\extern\include\mclmcr.h|1261|extraneous old-style parameter list|
mcctest.cpp: C:\Program Files\MATLAB\R2011a\extern\include\mclmcr.h|1264|syntax error; found `*' expecting `)'|
mcctest.cpp: C:\Program Files\MATLAB\R2011a\extern\include\mclmcr.h|1264|skipping `*' `ptr' `,'|
mcctest.cpp: C:\Program Files\MATLAB\R2011a\extern\include\mclmcr.h|1264|syntax error; found `)' expecting `;'|
mcctest.cpp: C:\Program Files\MATLAB\R2011a\extern\include\mclmcr.h|1264|skipping `)'|
mcctest.cpp: C:\Program Files\MATLAB\R2011a\extern\include\mclmcr.h|1267|syntax error; found `sp' expecting `)'|
mcctest.cpp: C:\Program Files\MATLAB\R2011a\extern\include\mclmcr.h|1267|skipping `sp' `,'|
mcctest.cpp: C:\Program Files\MATLAB\R2011a\extern\include\mclmcr.h|1267|extraneous old-style parameter list|
mcctest.cpp: C:\Program Files\MATLAB\R2011a\extern\include\mclmcr.h|1267|too many errors|
||=== Build finished: 20 errors, 0 warnings ===|
I get almost exactly the same errors when I run "mbuild mcctest.cpp libtest.lib" in Matlab using the LCC compiler:
String found where operator expected at (eval 78) line 1, near "'"if exist ''.$ENV{'"
(Missing operator before '.$ENV{'?)
String found where operator expected at (eval 79) line 1, near "'"if exist ''.$ENV{'"
(Missing operator before '.$ENV{'?)
String found where operator expected at (eval 80) line 1, near "'"if exist ''.$ENV{'"
(Missing operator before '.$ENV{'?)
String found where operator expected at (eval 81) line 1, near "'"if exist ''.$ENV{'"
(Missing operator before '.$ENV{'?)
lcc preprocessor error: mcctest.cpp:1 Could not find include file <iostream>
Error mcctest.cpp: C:\PROGRA~1\MATLAB\R2011a\extern\include\mclmcr.h: 1251 syntax error; found `int32_t' expecting `}'
Error mcctest.cpp: C:\PROGRA~1\MATLAB\R2011a\extern\include\mclmcr.h: 1251 skipping `int32_t' `buffLen'
Error mcctest.cpp: C:\PROGRA~1\MATLAB\R2011a\extern\include\mclmcr.h: 1252 unrecognized declaration
Error mcctest.cpp: C:\PROGRA~1\MATLAB\R2011a\extern\include\mclmcr.h: 1255 syntax error; found `ptr' expecting `)'
Error mcctest.cpp: C:\PROGRA~1\MATLAB\R2011a\extern\include\mclmcr.h: 1255 skipping `ptr'
Error mcctest.cpp: C:\PROGRA~1\MATLAB\R2011a\extern\include\mclmcr.h: 1255 extraneous old-style parameter list
Error mcctest.cpp: C:\PROGRA~1\MATLAB\R2011a\extern\include\mclmcr.h: 1258 syntax error; found `*' expecting `)'
Error mcctest.cpp: C:\PROGRA~1\MATLAB\R2011a\extern\include\mclmcr.h: 1258 skipping `*' `ptr'
Error mcctest.cpp: C:\PROGRA~1\MATLAB\R2011a\extern\include\mclmcr.h: 1258 extraneous old-style parameter list
Error mcctest.cpp: C:\PROGRA~1\MATLAB\R2011a\extern\include\mclmcr.h: 1261 syntax error; found `ptr' expecting `)'
Error mcctest.cpp: C:\PROGRA~1\MATLAB\R2011a\extern\include\mclmcr.h: 1261 skipping `ptr'
Error mcctest.cpp: C:\PROGRA~1\MATLAB\R2011a\extern\include\mclmcr.h: 1261 extraneous old-style parameter list
Error mcctest.cpp: C:\PROGRA~1\MATLAB\R2011a\extern\include\mclmcr.h: 1264 syntax error; found `*' expecting `)'
Error mcctest.cpp: C:\PROGRA~1\MATLAB\R2011a\extern\include\mclmcr.h: 1264 skipping `*' `ptr' `,'
Error mcctest.cpp: C:\PROGRA~1\MATLAB\R2011a\extern\include\mclmcr.h: 1264 syntax error; found `)' expecting `;'
Error mcctest.cpp: C:\PROGRA~1\MATLAB\R2011a\extern\include\mclmcr.h: 1264 skipping `)'
Error mcctest.cpp: C:\PROGRA~1\MATLAB\R2011a\extern\include\mclmcr.h: 1267 syntax error; found `sp' expecting `)'
Error mcctest.cpp: C:\PROGRA~1\MATLAB\R2011a\extern\include\mclmcr.h: 1267 skipping `sp' `,'
Error mcctest.cpp: C:\PROGRA~1\MATLAB\R2011a\extern\include\mclmcr.h: 1267 extraneous old-style parameter list
Error mcctest.cpp: C:\PROGRA~1\MATLAB\R2011a\extern\include\mclmcr.h: 1267 too many errors
C:\PROGRA~1\MATLAB\R2011A\BIN\MEX.PL: Error: Compile of 'mcctest.cpp' failed.
??? Error using ==> mbuild at 189
Unable to complete successfully.
*Anyone ever ran into the same problem before? Anyone found a solution?
Looking forward to some clue! Thanks!*
0 Kommentare
Antworten (1)
Kaustubha Govind
am 27 Jun. 2012
You may want to correct your question because the word S-function is misleading. From what I can tell by looking at your code, you are simply writing a driver application to call into the DLL generated by MATLAB Compiler, which has nothing to do with S-functions.
I would recommend that you follow the tutorial Integrate C Shared Libraries from the MATLAB Compiler documentation to understand exactly what header files and libraries are required.
Siehe auch
Kategorien
Mehr zu C Shared Library Integration finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!