error in using calllib

I am using Microsoft visual studio 2008 and MATLAB 7.11.0(R2010b) 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.
please help me

1 comentario

Philip Borghesani
Philip Borghesani el 17 de Dic. de 2012
Do you recive any warnings when you load the library? What is the output of libfunctions t1? If you issue the command:
NotFound=loadlibrary('t1.dll', 't1header.h');
What is the content of NotFound?

Iniciar sesión para comentar.

Respuestas (2)

Walter Roberson
Walter Roberson el 14 de Dic. de 2012

0 votos

That could mean that Add was not found in the library.
In the code that defines Add, is that code C or C++ ? If it is C++, is it in a
extern "C"
section? If it is C++ and is not in an extern C section, then internally it would not be known by the name Add . (This is a deliberate design feature of C++ in order to prevent accidental calling of a C++ routine without a proper "this" object in place.)

3 comentarios

Bency Baby
Bency Baby el 17 de Dic. de 2012
Editada: Walter Roberson el 17 de Dic. de 2012
T1Header.h ----------
#ifndef _T1_HEADER_H_
#define _T1_HEADER_H_
/*check if the compiler is of C++*/
#ifdef __cplusplus
extern "C" {
int Add( int a, int b );
}
#endif
#endif
T1Header.cpp
------------
#include "stdafx.h"
#include <stdio.h>
#include "T1Header.h"
extern "C" int Add( int a, int b )
{
return( a + b );
}
These are the files.
still this error is coming
calllib('T1Header','Add',2,3)
??? Error using ==> calllib Method was not found.
Walter Roberson
Walter Roberson el 17 de Dic. de 2012
I'm sure I answered this...
You are attempting to call upon a function named Add, passing to it two double numbers. Your routine defines a function named Add that accepts int numbers. You must match the type of parameter you are passing with the type of parameter the routine accepts.
Reminder, in MATLAB,
A = 2
defines A to be double, not integer. It is exactly the same as if you had used
A = 2.0000000;
or
A = 0.02E+2
Whereas
A = uint8(2)
would assign an 8 bit unsigned integer to A.
The number of bits in an "int" depends upon your C++ compiler.
Philip Borghesani
Philip Borghesani el 17 de Dic. de 2012
Calllib will automatically convert all simple data types for you. The types are not the problem. Matlab matrices are also automatically converted to native pointer types to a vector/matrix.

Iniciar sesión para comentar.

Philip Borghesani
Philip Borghesani el 17 de Dic. de 2012

0 votos

Given the header and code you posted it looks like you are not exporting your function from the library. Read up on building a DLL with exported functions and the declspec compiler extension. Dependency walker can be used to verify that the function was correctly exported without name mangling.

Categorías

Productos

Etiquetas

Preguntada:

el 14 de Dic. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by