在64位matlab上编译32位的动态链接库DLL文件

参考资料
https://www.mathworks.com/help/coder/ug/build-32-bit-dll-on-64-bit-windows®-platform-using-msvc-toolchain.html

完整代码
https://download.csdn.net/download/rmrgjxeivt/12277467

具体方法见代码

%% Check Platform and Determine MSVC Version
% This code checks that the platform is supported and that you have a
% supported version of Microsoft? Visual C/C++. The my_msvc_32bit_tc.m
% toolchain definition can use the Microsoft? Visual Studio versions 9.0,
% 10.0, 11.0, 12.0, 14.0, or 15.0. If you are not using a Windows?
% platform, or if you do not have a supported version of Microsoft? Visual
% C/C++, the example generates only code and a makefile, without running
% the generated makefile.
VersionNumbers = {'14.0'}; % Placeholder value
if ~ispc
    supportedCompilerInstalled = false;
else
    installed_compilers = mex.getCompilerConfigurations('C', 'Installed');
    MSVC_InstalledVersions = regexp({installed_compilers.Name}, 'Microsoft Visual C\+\+ 20\d\d');
    MSVC_InstalledVersions = cellfun(@(a)~isempty(a), MSVC_InstalledVersions);
    if ~any(MSVC_InstalledVersions)
        supportedCompilerInstalled = false;
    else
        VersionNumbers = {installed_compilers(MSVC_InstalledVersions).Version}';
        supportedCompilerInstalled = true;
    end
end
%% Create and Configure an MSVC Toolchain
tc = my_msvc_32bit_tc(VersionNumbers{end});
save my_msvc_32bit_tc tc;
%% Register the Toolchain
copyfile myRtwTargetInfo.txt rtwTargetInfo.m
RTW.TargetRegistry.getInstance('reset');
%% Create Code Generation Configuration Object
cfg = coder.config('dll');
%% Configure Code Generation for 32-bit Hardware
cfg.HardwareImplementation.ProdHWDeviceType = ...
    'Generic->Unspecified (assume 32-bit Generic)';
%% Configure Code Generation to Use the 32-bit Toolchain
cfg.Toolchain = ...
    'Microsoft 32 Bit Toolchain | nmake makefile (64-bit Windows)';
%% Select Verbose Status Reporting
cfg.Verbose = true;
%% Determine Whether to Generate Code Only
if supportedCompilerInstalled
    cfg.GenCodeOnly = false;
else
    cfg.GenCodeOnly = true;
end
%% Generate Code and Build a DLL
% 在这里修改输入输出定义,函数名等参数
codegen -config cfg myMatlabFunction -args { double(1.0) };

%% Optional Step: Unregister the toolchain
% delete ./rtwTargetInfo.m
% RTW.TargetRegistry.getInstance('reset');

%% Build and Run an Executable
% cfge = coder.config('exe');
% cfge.CustomInclude = pwd;
% cfge.CustomSource = 'myMatlabFunction_main.c';
% cfge.GenCodeOnly = cfg.GenCodeOnly;
% cfge.Verbose = true;
% cfge.Toolchain = ...
%     'Microsoft 32 Bit Toolchain | nmake makefile (64-bit Windows)';
% codegen -config cfge myMatlabFunction -args { double(1.0) };
% if supportedCompilerInstalled
%     pause(5); %wait for EXE to get generated
%     system('myMatlabFunction 3.1416'); % Expected output: myMatlabFunction(3.1416) = 6.2832
% end
  • 1
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值