error in using calllib function

13 ビュー (過去 30 日間)
Mahnaz
Mahnaz 2012 年 8 月 17 日
i want to use callib function but it shows me an error?
>> loadlibrary('t1.dll', 't1header.h')
>> calllib('t1','Add',2,3)
??? Error using ==> calllib
Method was not found.
i have Add fuction but when i use libfunctionsview it shows me an error :
>> libfunctionsview('t1')
??? Error using ==> libfunctionsview at 47
No library t1 can be located or no functions for library t1
Any suggestions on what is wrong?
  4 件のコメント
Mahnaz
Mahnaz 2012 年 8 月 17 日
編集済み: Walter Roberson 2012 年 8 月 17 日
>> [notfound, warnings] = loadlibrary('t1', 't1header.h')
Warning: No functions found in library.
> In loadlibrary at 444
notfound =
Empty cell array: 1-by-0
warnings =
''
t1header is:
#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)/*DECLDIR*/ int Add( int a, int b );
__declspec(dllexport)/*DECLDIR*/ void Function( void );
}
#endif
and this is my source:
#include <stdio.h>
#include "t1header.h"
#define DLL_EXPORT
extern "C"
{
DECLDIR int Add( int a, int b )
{
return( a + b );
}
DECLDIR void Function( void )
{
printf("DLL Called.\n");
}
}
Walter Roberson
Walter Roberson 2012 年 8 月 17 日

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 8 月 17 日
loadlibrary('shrlib', 'hfile') loads the functions defined in header file hfile and found in shared library shrlib into MATLAB. You must select a supported C compiler and Perl must be available.
Notice that the above says "C compiler". Your .h file is written for C++ (which we can tell from the extern "C")
  1 件のコメント
Kaustubha Govind
Kaustubha Govind 2012 年 8 月 17 日
Mahnaz: Also, looks like Titus helped a little with on your previous question which looks like the same issue: http://www.mathworks.com/matlabcentral/answers/45337-connecting-matlab-to-c-language-dll

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeC Shared Library Integration についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by