自己写的简单的动态链接库,为什么matlab不能调用。

wendysen 2009-07-24 03:40:02
是按照书上的例子写的,不知道为什么在Matlab中不能调用。如下:

在VC++中 new一个Win32 Dynamic-Link Library工程,加入文件lib.cpp和lib.h:

/*文件名:lib.h*/
#ifndef LIB_H
#define LIB_H
int _stdcall add(int x,int y);
#endif

/*文件名: lib.cpp */
#include "lib.h"
int _stdcall add(int x,int y)
{
return x + y;
}


matlab中调用是,加载就出错:
>> loadlibrary('dllTest.DLL','dllTest.h')
Warning: The function 'add' was not found in the library 路径等都是对的
'dllTest.h'是我自己写的,就是lib.h的内容


不知道为什么在VC中可以用,在matlab中就是不可以用,试了几次都不行。请大侠多多指点...


...全文
442 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
yueyucanyang 2009-07-29
  • 打赏
  • 举报
回复
在dllTest.h:文件的最后一行键入个回车,重新生成库。头文件重新包含。要是在ccs环境下,程序最后一行应该是空行!~
horris 2009-07-28
  • 打赏
  • 举报
回复
必须用extern C,并且必须正确地导出,否则不是标准DLL!
VC能调用,是因为VC认识C++的导出函数,你这个DLL不仅matlab不能调用,其他的语言,如VB,C#等都不能调用的。
wendysen 2009-07-26
  • 打赏
  • 举报
回复
还是没有找到好的解决办法啊...
jyh_baoding 2009-07-24
  • 打赏
  • 举报
回复
应该可以
wendysen 2009-07-24
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 oyljerry 的回复:]
用c 方式导出 extern C
[/Quote]

用这个不可以,去掉extern C以后vc中可以用,看来问题应该是处在matlab这里了。
cyldf 2009-07-24
  • 打赏
  • 举报
回复
__declspec(dllexport)
oyljerry 2009-07-24
  • 打赏
  • 举报
回复
用c 方式导出 extern C
marrco2005 2009-07-24
  • 打赏
  • 举报
回复
The C language standard says
A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character.Since this is a "shall" clause, we must emit a diagnostic message for a violation of this rule.This is in section 2.1.1.2 of the ANSI C 1989 standard. Section 5.1.1.2 of the ISO C 1999 standard (and probably also the ISO C 1990 standard).

好像是 C 文件必须以一个回车作为结束符。
你在头文件里最后一行敲一个回车,保存,再编译试试
wendysen 2009-07-24
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 marrco2005 的回复:]
你的dll需要导出 add 函数
[/Quote]


修改后,matlab中有提示如下:
Warning: Message from C preprocessor:
lcc preprocessor warning: D:\MATLAB\R2008b\my work\DLL\dllTest.h:4 No newline at end of file


怎么改正呢?
marrco2005 2009-07-24
  • 打赏
  • 举报
回复
你的dll需要导出 add 函数
eagerle01 2009-07-24
  • 打赏
  • 举报
回复
不懂

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧