visual studio Dll and Matlab
visual studio Dll and Matlab
我正在尝试用visual studio构建一个dll,以便在matlab中使用它。。。我尝试了thausand代码,但没有解决方案!!!我正在开发matlab 2013(32和64)和VS2010!例如,我试着用这种方式编写代码。。。
//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);
}
visualstudio构建了它并制作了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
简单.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);
}
将生成的simple.dll
和头文件simple.h
、helper.h
复制到当前目录中。然后在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
注意:如果你运行的是MATLAB 64位,你必须建立这样的DLL。规则是不能在64位进程中加载32位库。
相关文章:
- 在C++STL中是否有Polyval(Matlab函数)等价物?
- 有可能在Armadillo中复制MATLAB circshift方法吗
- C++核心准则 C35 对于接口类"A base class destructor should be either public and virtual, or protected and nonv
- 使用 MATLAB 编码器生成C++代码:编译错误"undefined reference to `rgb2gray_tbb_real64'"
- 为什么C++逐位AND运算符在不同大小的操作数中表现为这样
- 为什么 Clang 不允许"and"作为函数名称?
- 位阵列上的快速AND运算
- 是否可以在 C++03 中定义'move-and-swap idiom'等效项
- BoostPython and CMake
- OpenSSL BIO and SSL_read
- Gurobi GRBModel and GRBmodel in C++
- std::visit and std::variant usage
- MATLAB to C++: csvread() not supported by MATLAB Coder
- SHBrowseForFolder with BIF_BROWSEFORCOMPUTER and SHGetPathFr
- FFT and FFTShift of matlab in FFTW library c++
- Matlab Coder and Arduino IDE emxCreateWrapper_real_T
- cv::remap (in opencv) and interp2 (matlab)
- rgb2lab discrepancy opencv and matlab
- visual studio Dll and Matlab
- Matlab rand and c++ rand()