【问题标题】:Compile the C-file in MATLAB在 MATLAB 中编译 C 文件
【发布时间】:2015-05-20 02:50:54
【问题描述】:

说明

我有一个 Mathematica MATLAB 符号工具箱--2.0 版 here

然后我使用它包含的文档在 MATLAB 环境中编译

安装步骤:

  • 1) 转到您的 Mathematica 目录并在其中找到文件 mathlink.h E:\math\Mathematica\5.\AddOns\MathLink\DeveloperKit\Windows\CompilerAdditions\mldev32\include' 还有文件ml32i1m.lib in E:\math\Mathematica\5.\AddOns\MathLink\DeveloperKit\Windows\CompilerAdditions\mldev32\lib。将这两个文件复制到预定目录(我们将此目录称为 C:\xxx)。
  • 2) 将压缩文件math.tar的内容复制到C:\xxx.
  • 3) 打开 Matlab 命令窗口并执行mex –setup。选择“Microsoft Visual C/C++ version 6.0 in C:\Program Files\Microsoft Visual Studio”。这告诉 Matlab 它需要使用 C 编译器(而不是 Fortran 编译器)。您需要安装 Microsoft Visual C/C++。不要选择“Lcc C version 2.4 in C:\MATLAB6P1\sys\lcc”选项。 4) 打开 Matlab 命令窗口并运行 mathrun.m。该程序将编译 C 文件 math.c

我得到的文件如下所示:

然后我一步一步做

(1)在以下路径中找到mathlink.hml32i1m.lib

D:\WolframResearch\Mathematica\8.0\SystemFiles\Links\MathLink\DeveloperKit\Windows\CompilerAdditions\mldev32\include D:\Wolfram Research\Mathematica\8.0\SystemFiles\Links\MathLink\DeveloperKit\Windows\CompilerAdditions\mldev32\lib

(2)将压缩文件math.zip的内容复制到C:\XXX

(3) 在MATLAB中编译

  mex -setup

(4)最后一次设置

addpath C:\XXX
run mathrun.m

不知道为什么?


更新

mathrun.m中的matlab代码

addpath C:\XXX; 
% adds the directory C:\XXX to the list of directories which Matlab "sees" (referred to as paths)
mlpath='C:\XXX'   % The directory where mathlink.h is
mllib='C:\XXX\ml32i1m.lib'   % The library ml32i1m.lib

% make command
command=sprintf('mex -D__STDC __ -I % s % s % s', mlpath, 'math.c', mllib);
% compile
eval(command)  

【问题讨论】:

  • 这个工具箱出现在 2004 年,是为现在相当古老的 Matlab 和 Mathematica 版本编写的。你有什么 version 的 Matlab?还有 Mathematica?
  • @horchler - 从最后一张快照来看,它看起来像是 R2012b....但我认为如果从 2004 年开始,OP 没有任何机会运行工具箱。
  • @horchler,我的 MATLAB 版本是 2012b,另外,*Mathematica *版本是 8.0.4
  • 错误最后一行 caller 周围的引号对我来说看起来不对。这是错误的原因吗?您可以逐行调试并帮助自己。除非您能提供具体的错误来源,否则我怀疑是否有人可以提供帮助。
  • @ParagS.Chandakkar,谢谢,请看我的更新:)

标签: matlab compilation wolfram-mathematica mex


【解决方案1】:

好像路径没有正确传递给mex,所以找不到math.c。注释原行:

%command=sprintf('mex -D__STDC __ -I % s % s % s', mlpath, 'math.c', mllib);

然后添加这个:

command=sprintf('mex -D__STDC __ -I%s %s %s', mlpath, 'math.c', mllib);

因为mex 文档指定-I 开关和输入路径之间不应有空格。为了安全起见,你甚至可以写:

command=sprintf('mex -D__STDC __ -I%s %s %s', mlpath, fullfile(mlpath,'math.c'), mllib);

【讨论】:

  • 非常感谢您的解决方案。但是,command=sprintf('mex -D__STDC __ -I%s %s %s', mlpath, 'math.c', mllib); 给出了警告信息 `D:\MATLAB\R2012B\BIN\MEX.PL: Error: '' not found.`。此外,command=sprintf('mex -D__STDC __ -I%s %s %s', mlpath, fullfile(mlpath,'math.c'), mllib); 还给出了 `D:\MATLAB\ R2012B\BIN\MEX.PL:错误:找不到“”。`
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-28
  • 1970-01-01
  • 2015-02-27
  • 1970-01-01
  • 2021-08-19
  • 1970-01-01
相关资源
最近更新 更多