视觉工作室Dll和Matlab [英] visual studio Dll and Matlab
问题描述
我尝试了没有解决方案的代码!我正在使用matlab 2013(32and64)和VS2010!
我试着用这种方式写代码...
//标题
#ifndef SIMPLEH_H
#define SIMPLEH_H
#ifdef __cplusplus
externC{
int sq(int x);
#endif
#ifdef __cplusplus
}
#endif
#endif
// Func(示例)
#includeSimpleH.h
int sq(int x)
{
return(x * x);
}
visual studio构建并制作dll文件,但matlab始终看不到函数...
我应该怎么做/ *我真的卡住了:( * /
提前感谢...
示例:获取以下文件,并在Visual Studio中构建一个DLL。
helper.h
#ifndef HELPER_H
#define HELPER_H
#ifdef _WIN32
#ifdef EXPORT_FCNS
#define EXPORTED_FUNCTION __declspec(dllexport)
#else
#define EXPORTED_FUNCTION __declspec(dllimport)
#endif
#else
#define EXPORTED_FUNCTION
#endif
#endif
simple.h
#ifndef SIMPLEH_H
#define SIMPLEH_H
#includehelper.h
#ifdef __cplusplus
externC{
#endif
EXPORTED_FUNCTION int sq(int x);
#ifdef __cplusplus
}
# endif
#endif
simple.cpp
#define EXPORT_FCNS
#includehelper.h
#includesimple.h
int sq(int x)
{
return(x * x);
}
复制生成的 simple.dll
和当前目录中的头文件 simple.h
和 helper.h
。然后在MATLAB中:
>> loadlibrary('./ simple.dll','./simple.h')
>> libisloaded简单
ans =
1
>> libfunctions simple -full
库中的函数简单:
int32 sq(int32)
>> calllib('simple','sq',3)
ans =
9
注意:如果您正在运行MATLAB 64位,则必须构建DLL。规则是您无法在64位进程中加载32位库。
I am trying to build a dll with visual studio so I can use it in matlab ... I tried thausand codes with no solution !!! I am working on matlab 2013(32and64) and VS2010 ! I tried for example to write the code this way ...
//The header
#ifndef SIMPLEH_H
#define SIMPLEH_H
#ifdef __cplusplus
extern "C" {
int sq(int x);
#endif
#ifdef __cplusplus
}
#endif
#endif
//the Func(example)
#include "SimpleH.h"
int sq(int x)
{
return (x*x);
}
visual studio Build it and make th dll file but matlab always doesn't see the function ... What should I do /* I am really stucked :( */ Thanks in advance ...
Example: Take the following files, and build a DLL in Visual Studio.
helper.h
#ifndef HELPER_H
#define HELPER_H
#ifdef _WIN32
#ifdef EXPORT_FCNS
#define EXPORTED_FUNCTION __declspec(dllexport)
#else
#define EXPORTED_FUNCTION __declspec(dllimport)
#endif
#else
#define EXPORTED_FUNCTION
#endif
#endif
simple.h
#ifndef SIMPLEH_H
#define SIMPLEH_H
#include "helper.h"
#ifdef __cplusplus
extern "C" {
#endif
EXPORTED_FUNCTION int sq(int x);
#ifdef __cplusplus
}
#endif
#endif
simple.cpp
#define EXPORT_FCNS
#include "helper.h"
#include "simple.h"
int sq(int x)
{
return (x*x);
}
Copy the generated simple.dll
and the header files simple.h
and helper.h
in the current directory. Then in MATLAB:
>> loadlibrary('./simple.dll', './simple.h')
>> libisloaded simple
ans =
1
>> libfunctions simple -full
Functions in library simple:
int32 sq(int32)
>> calllib('simple', 'sq',3)
ans =
9
Note: If you are running MATLAB 64-bit, you must build the DLL as such. The rule is that you cannot load a 32-bit library in a 64-bit process.
这篇关于视觉工作室Dll和Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!