connecting matlab to c++ language dll
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
hello
i'm trying to use clllib function in matlab i put .dll file and .h file in the same directory as the .m MATLAB file being developed and after that i try to use loadlibrary function bui it have two warnings:
l oadlibrary('t1.dll','T1Header.h') Warning: Message from C preprocessor: lcc preprocessor error: C:\Users\MAHNAZ\Documents\MATLAB\T1Header.h:1 Could not find include file iostream lcc preprocessor warning: C:\Users\MAHNAZ\Documents\MATLAB\T1Header.h:18 No newline at end of file
when i want to use calllib function like this:
calllib('t1', 'Add', 2,3)
matlab give me an error:
??? Error using ==> calllib
Method was not found.
my header file is:
#include <iostream>
#ifndef _T1_HEADER_H_
#define _T1_HEADER_H_
#if defined DLL_EXPORT
#define DECLDIR __declspec(dllexport)
#else
#define DECLDIR __declspec(dllimport)
#endif
extern "C"
{
__declspec(dllexport) int Add( int a, int b );
__declspec(dllexport) void Function( void );
}
#endif
i use visual c++ 2010
Any suggestions on what is wrong, what I could do to fix this error, or what else I could try to call this .dll from within MATLAB?
thanks!
0 Kommentare
Antworten (2)
Titus Edelhofer
am 6 Aug. 2012
Hi,
did you tell MATLAB to use visual studio as well? Looks as if it uses LCC, the C compiler that comes bundled with MATLAB. Do a
mex -setup
and choose your visual studio, that should help.
Titus
2 Kommentare
Kaustubha Govind
am 6 Aug. 2012
This is the list of supported compilers for R2008a - Visual Studio 2010 is not on the list, which is why "mex -setup" doesn't find it. I would recommend installing one of the supported compilers and answer "y" to "Would you like mex to locate installed compilers [y]/n?" - because if MATLAB is unable to find your compiler automatically, there is usually something wrong with your compiler setup.
(Note: You cannot use the LCC compiler to preprocess a C++ header, because it is a C-only compiler, so Titus' solution of converting your header to C-style should work with LCC)
Titus Edelhofer
am 6 Aug. 2012
Hmm, I just took another look on your question: probably the easiest thing to do is to write a second header file just containing the declarations:
extern int Add( int a, int b );
extern void Function( void );
and use this file to call loadlibrary.
Titus
3 Kommentare
Titus Edelhofer
am 7 Aug. 2012
Bearbeitet: Walter Roberson
am 17 Aug. 2012
iostream is C++, lcc is C, so you need to
- remove the "include iostream" line
- add #include <stdio.h>
- replace the cout line by
printf("DLL Called.\n");
Titus
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!