在MATLAB中编译C文件 描述
我有一个Mathematica符号工具箱用于MATLAB——版本2.0 然后我使用它附带的文档在MATLAB环境下编译 安装步骤:在MATLAB中编译C文件 描述,matlab,compilation,wolfram-mathematica,mex,Matlab,Compilation,Wolfram Mathematica,Mex,我有一个Mathematica符号工具箱用于MATLAB——版本2.0 然后我使用它附带的文档在MATLAB环境下编译 安装步骤: 1) 转到Mathematica目录,在中找到文件mathlink.h E:\math\Mathematica\5.\AddOns\MathLink\DeveloperKit\Windows\CompilerAdditions\mldev32\include' 以及中的文件ml32i1m.lib E:\math\Mathematica\5.\AddOns\Math
- 1) 转到Mathematica目录,在中找到文件
E:\math\Mathematica\5.\AddOns\MathLink\DeveloperKit\Windows\CompilerAdditions\mldev32\include' 以及中的文件mathlink.h
E:\math\Mathematica\5.\AddOns\MathLink\DeveloperKit\Windows\CompilerAdditions\mldev32\lib。将两个文件复制到预定的目录(我们将此目录称为C:\xxx)ml32i1m.lib
- 2) 将压缩文件math.tar的内容复制到C:\xxx中
- 3) 打开Matlab命令窗口并执行
。选择“C:\Program Files\Microsoft Visual Studio中的Microsoft Visual C/C++6.0版”。这告诉Matlab它需要使用C编译器(与Fortran编译器相反)。您需要安装Microsoft Visual C/C++。不要选择“C:\MATLAB6P1\sys\Lcc中的Lcc版本2.4”选项。 4) 打开Matlab命令窗口并运行mathrun.m。此程序将编译C文件mex–setup
math.C
mathlink.h
和ml32i1m.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) 最后一组
我不知道为什么
更新
mathrun.m
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)
似乎路径未正确传递到
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);
这个工具箱似乎是从2004年开始的,是为现在非常古老的Matlab和Mathematica版本编写的。你有什么版本的Matlab?“那Mathematica呢?”霍奇勒-从上一张快照判断,它看起来像是R2012b。。。。但是如果是2004年的,我认为OP没有机会运行工具箱。@horchler,我的MATLAB版本是2012b,Inadtion,*Mathematica*版本是8.0.4错误最后一行中调用方的引号对我来说是错误的。这就是错误的原因吗?你可以一行一行地调试,自己动手。除非您能给出具体的错误源,否则我怀疑是否有人能提供帮助。@ParagS.Chandakkar,Thks,请查看我的更新:)非常感谢您的解决方案。但是,
command=sprintf('mex-D_ustdc-I%s%s%s',mlpath',math.c',mllib)
给出警告信息'D:\MATLAB\R2012B\BIN\MEX.PL:错误:''未找到。`。此外,command=sprintf('MEX-D\uu STDC\uuuu-I%s%s%s',mlpath,fullfile(mlpath,'math.c'),mllib)
还提供了“D:\MATLAB\R2012B\BIN\MEX.PL:找不到错误:“”`
command=sprintf('mex -D__STDC __ -I%s %s %s', mlpath, fullfile(mlpath,'math.c'), mllib);