2012-08-07 95 views
0

我想在matlab中使用clllib函数,我把.dll文件和.h文件放在与开发的.m MATLAB文件相同的目录下,之后我尝试使用loadlibrary function bui它有一些警告将matlab连接到c语言的DLL

警告:

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:21 EOF inside comment 

> In loadlibrary at 351 

Warning: The function 'Add' was not found in the library 

> In loadlibrary at 435 

Warning: The function 'Function' was not found in the library 

> In loadlibrary at 435 

,当我想用​​calllib功能就像这样:calllib('t1', 'Add', 2,3) MATLAB给我一个错误:

??? Error using ==> calllib Method was not found. 

我的头文件是:

#ifndef T1_HEADER_H 
#define T1_HEADER_H 
extern int Add(int a, int b); 
extern void Function(void); 
#endif 

我的源文件是:

#include iostream 
#include "T1Header.h" 

    extern int Add(int a, int b) 
    { 
     return(a + b); 
    } 

    extern void Function(void) 
    { 
    std::cout << "DLL Called!" << std::endl; 
    } 

我使用Visual C++ 2010和Matlab 7.6.0(R2008a)

什么是错的任何建议,有什么我可以修复这个错误,或者我可以尝试从MATLAB内部调用这个.dll文件。

回答

0

一些注意事项和注释前面:

  • 错误装载的iostream听起来有点像代码正在处理为C,而不是C++。
  • 粘贴的源文件在名称iostream的周围没有斜角,但是我猜这些文章在你写这篇文章时会丢失。
  • 定义它们时,功能不应该是extern
  • 您粘贴的错误消息提到了一个未包含在您的粘贴中的注释。
  • 我有点惊讶,matlab甚至看着头,我会假定它只使用DLL文件。

但最主要的原因对于这个问题,假设DLL文件得到了最终产生,应该是这样的:Matlab的可能会想使用C调用约定,所以你应该括在无论是在extern "C" { … }块的功能头文件和实现中。

+0

我改变头文件和源文件: 外部的 “C” { INT添加(INT A,INT B) { 返回(A + B); } \t void函数(无效) { \t的printf( “DLL调用\ n”); } } >>的LoadLibrary( 't1.dll', 'T1Header.h') 警告:消息从C预处理: LCC预处理器警告:C:\用户\玛赫纳兹\文件\ MATLAB \ T1Header。H:21没有换行符在 文件 >在调用LoadLibrary结束在351 警告:函数“添加”没有在435 警告库 >在调用LoadLibrary发现:该功能“功能”是不是在库中找到 和calllib函数找不到ADD方法 – mahnaz0098 2012-08-08 10:53:01