MATLAB调用DLL

- MATLAB版本 2017a

- VS版本 VS2015

 

参考如下步骤:

1、新建一个c++ DLL工程MatlabDllTest

2、头文件

#pragma once


#ifndef MATLABDLLTEST_H
#define MATLABDLLTEST_H


#ifdef __cplusplus
extern "C"
{
#endif

	__declspec(dllexport) double add(double x, double y);

#ifdef __cplusplus
}
#endif
#endif

3、cpp文件

// MatlabDllTest.cpp : 定义 DLL 应用程序的导出函数。
//

#include "stdafx.h"

#include "MatlabDllTest.h"

double add(double x, double y)
{
	return (x + y);
}



选择x64平台生成MatlabDllTest.dll

 

4、MATLAB中加载DLL

loadlibrary('MatlabDllTest','MatlabDllTest.h');

5、MAT中调用函数

calllib('MatlabDllTest', 'add', 1.3, 4.6)

 

note:

如果加载的时候报错:

 

需要在VS中修改项目属性:

修改c/c++->代码生成->运行库设置为:多线程调试(/MTd)

 

参考链接:

https://www.jianshu.com/p/e910ca82b542

https://blog.youkuaiyun.com/so_geili/article/details/53009680

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值