MATLAB2014b怎么在Linux14.04下exob反编译破解软件mex文件

Ubuntu 14.04下用GCC及gfortran编写MEX程序(Matlab2012a)_Linux编程_Linux公社-Linux系统门户网站
你好,游客
Ubuntu 14.04下用GCC及gfortran编写MEX程序(Matlab2012a)
来源:oschina.net&
作者:wxwpxh
14.04下用GCC及gfortran编写MEX程序(Matlab2012a)
一、先用apt-get安装一个低版本gcc
& & sudo apt-get install gcc-4.4 g++-4.4 gfortran-4.4
& & matlab2012a可以支持到最高为4.4版本的gcc,而ubuntu14.04默认的gcc版本为4.8
二、修改mexopts.sh
& & sudo vi /opt/MATLAB/R2012a/bin/mexopts.sh
& & 将所有的gcc、g++、gfortran出现分别替换成gcc-4.4、g++-4.4、gfortran-4.4
& & 将CFLAGS='-ansi -D_GNU_SOURCE'改为CFLAGS='-std=c99 -D_GNU_SOURCE'以支持//风格注释
三、启动matlab执行mex -setup命令
&& mex -setup
& & Options files control which compiler to use, the compiler and link command
& & options, and the runtime libraries to link against.
& & Using the 'mex -setup' command selects an options file that is
& & placed in /home/mymotif/.matlab/R2012a and used by default for 'mex'. An options
& & file in the current working directory or specified on the command line
& & overrides the default options file in /home/mymotif/.matlab/R2012a.
& & To override the default options file, use the 'mex -f' command
& & (see 'mex -help' for more information).
The options files available for mex are:
& 1: /opt/local/MATLAB/R2012a/bin/mexopts.sh :
& & & Template Options file for building gcc-4.4 MEX-files
& 0: Exit with no changes
Enter the number of the compiler (0-1):
/opt/local/MATLAB/R2012a/bin/mexopts.sh is being copied to
/home/mymotif/.matlab/R2012a/mexopts.sh
**************************************************************************
& Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements.& In the near future
you will be required to update your code to utilize the new
API. You can find more information about this at:
/help/techdoc/matlab_external/bsflnue-1.html
Building with the -largeArrayDims option enables the new API.
**************************************************************************
(1)进入matlab工作目录,并创建源文件hello1.c内容如下:
#include "mex.h"void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){& && & i=mxGetScalar(prhs[0]);& & if(i==1)& & & & mexPrintf("hello,world!\n");& & else& & & & mexPrintf("大家好!\n");}&
&& mex hello1.c
&& hello1(0)
&& hello1(1)
hello,world!
mexFunction 输入参数含义
int& nlhs :输出 参数的 个数
mxArray& *& plhs :输出参数的 mxArray数组
int& nrhs :输入 参数的 个数
mxArray& *& prhs: 输入参数的 mxArray 数组
(2)g++例子:
mexcpp.cpp&/*==========================================================&* mexcpp.cpp - example in MATLAB External Interfaces&*&* Illustrates how to use some C++ language features in a MEX-file.&* It makes use of member functions, constructors, destructors, and the&* iostream.&*&* The routine simply defines a class, constructs a simple object,&* and displays the initial values of the internal variables.& It&* then sets the data members of the object based on the input given&* to the MEX-file and displays the changed values.&*&* This file uses the extension .cpp.& Other common C++ extensions such&* as .C, .cc, and .cxx are also supported.&*&* The calling syntax is:&*&*& &
mexcpp( num1, num2 )&*&* Limitations:&* On Windows, this example uses mexPrintf instead cout.& Iostreams &* (such as cout) are not supported with MATLAB with all C++ compilers.&*&* This is a MEX-file for MATLAB.&* Copyright
The MathWorks, Inc.&*&*========================================================*//* $Revision: 1.5.4.4 $ */&#include &iostream&#include &math.h&#include "mex.h"&&extern void _main();&/****************************/class MyData {&public:& void display();& void set_data(double v1, double v2);& MyData(double v1 = 0, double v2 = 0);& ~MyData() { }private:& double val1, val2;};&MyData::MyData(double v1, double v2){& val1 = v1;& val2 = v2;}&void MyData::display(){#ifdef _WIN32& & mexPrintf("Value1 = %g\n", val1);& & mexPrintf("Value2 = %g\n\n", val2);#else& cout && "Value1 = " && val1 && "\n";& cout && "Value2 = " && val2 && "\n\n";#endif}&void MyData::set_data(double v1, double v2) { val1 = v1; val2 = v2; }&/*********************/&staticvoid mexcpp(& & & & double num1,& & & & double num2& & & & ){#ifdef _WIN32& & mexPrintf("\nThe initialized data in object:\n");#else& cout && "\nThe initialized data in object:\n";#endif& MyData *d = new MyD // Create a& MyData object& d-&display();& & & & &
// It should be initialized to& & & & & & & & & & & & & // zeros& d-&set_data(num1,num2); // Set data members to incoming& & & & & & & & & & & & & // values#ifdef _WIN32& mexPrintf("After setting the object's data to your input:\n");#else& cout && "After setting the object's data to your input:\n";#endif& d-&display();& & & & &
// Make sure the set_data() worked& delete(d);& flush(cout);&}&void mexFunction(& & & &
int& & & & & nlhs,& & & &
mxArray& & & *[],& & & &
int& & & & & nrhs,& & & &
const mxArray *prhs[]& & & &
){& double& & & *vin1, *vin2;&& /* Check for proper number of arguments */&& if (nrhs != 2) {& & mexErrMsgIdAndTxt("MATLAB:mexcpp:nargin", & & & & & & "MEXCPP requires two input arguments.");& } else if (nlhs &= 1) {& & mexErrMsgIdAndTxt("MATLAB:mexcpp:nargout",& & & & & & "MEXCPP requires no output argument.");& }&& vin1 = (double *) mxGetPr(prhs[0]);& vin2 = (double *) mxGetPr(prhs[1]);&& mexcpp(*vin1, *vin2);&}&
&& mex mexcpp.cpp
&& mexcpp(2,4)
The initialized data in object:
Value1 = 0
Value2 = 0
After setting the object's data to your input:
Value1 = 2
Value2 = 4
(3)gfortran
# include &fintrf.h&&& & & subroutine mexFunction ( nlhs, plhs, nrhs, prhs )&c*********************************************************************72ccc MEXFUNCTION is a MATLAB/F77 interface for the factorial function.cc& Discussion:cc& & The MATLAB user typesc c& & integer plhs(*), prhs(*)c& & integer nlhs, nrhs&& & & integer nlhs& & & integer nrhs&&& & & mwpointer plhs(nlhs)& & & mwpointer prhs(nrhs)&& & & call mexPrintf('Hello MATLAB World!')&& & & return& & & end
&& mex mexHelloWorld.F
&& mexHelloWorld
Hello MATLAB World!&&
Ubuntu下GCC、G++和gfortran版本切换
Linux升级GCC 4.8.1清晰简明教程(Ubuntu 12.04 64位版为例)&
在 6.4中编译安装GCC 4.8.1 + GDB 7.6.1 + Eclipse 在CentOS 6.4中编译安装GCC 4.8.1 + GDB 7.6.1 + Eclipse
Ubuntu下Vim+GCC+GDB安装及使用&
Ubuntu下两个GCC版本切换&
CentOS6.5升级手动安装GCC4.8.2&
GCC 的详细介绍:GCC 的下载地址:
更多Ubuntu相关信息见 专题页面
本文永久更新链接地址:
相关资讯 & & &
& (05月03日)
& (01月19日)
& (05月12日)
& (03月29日)
& (08/24/:14)
   同意评论声明
   发表
尊重网上道德,遵守中华人民共和国的各项有关法律法规
承担一切因您的行为而直接或间接导致的民事或刑事法律责任
本站管理人员有权保留或删除其管辖留言中的任意内容
本站有权在网站内转载或引用您的评论
参与本评论即表明您已经阅读并接受上述条款4198人阅读
matlab(1)
linux(16)
本文主要记录,Linux下matlab的m文件的编译以及执行过程
安装matlab_linux,linux下matlab的下载以及安装的参考连接,/read-htm-tid-6280022.html。启动matlab,在matlab命令行上设置编译器,使用命令如下:
mex -setup
启动编译工具,deploytool,命令如下,安装图形界面添加需要编译的文件,并开始编译,可以编译成可执行文件或者动态链接库。若希望直接执行,编译成动可执行文件即可,若和其他语言混编,可以做成动态链接库,可以根据需要在图形界面上进行配置。本实验是做成一个可执行文件。
deploytool
假设应用程序名称为,Test,这编译完成后会生成一个Test文件夹,我们需要的可执行文件就在Test/distrib目录下。此时distrib 目录下面有两个文件,一个是run_Test.sh脚本文件和Test可执行文件。此时执行run_Test.sh文件,并不能执行,因为在Linux下,默认不会安装MCR,需要手动安装,MCR所在的路径为:matlab按照路径/toolbox/compiler/deploy/glnx86。安装完MCR后,执行如下命令,即可执行编译生成的Test文件。
run_Test.sh MCR_Install_Dir
若不想使用run_Test.sh脚本,直接运行Test文件,只需要设置两个环境变量即可,分别是:
export XAPPLRESDIR=/opt/matlab2009b/X11/app-defaultsLD_LIBRARY_PATH=/opt/matlab2009b/runtime/glnx86:/opt/matlab2009b/bin/glnx86:/opt/matlab2009b/sys/os/glnx86:/opt/matlab2009b/sys/java/jre/glnx86/jre/lib/i386/native_threads:/opt/matlab2009b/sys/java/jre/glnx86/jre/lib/i386/server:/opt/matlab2009b/sys/java/jre/glnx86/jre/lib/i386/client:/opt/matlab2009b/sys/java/jre/glnx86/jre/lib/i386其中,/opt/matlab2009b,为matlab的安装路径,此时可以直接运行,Test文件了。
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:187131次
积分:2476
积分:2476
排名:第14868名
原创:77篇
转载:13篇
评论:87条
(1)(2)(1)(1)(1)(3)(1)(3)(1)(3)(8)(3)(3)(2)(1)(4)(1)(1)(5)(2)(1)(2)(1)(5)(3)(9)(1)(1)(3)(3)(4)(10)Matlab&2012b中mex&编译cpp文件
今天在找到了一代码包,里面有cpp文件,需要通过编译器转成*.mexw64文件。我发现matlab2012b居然没有编译器。这台装了matlab2012b的电脑没有装VC++6.0、VS2010等。。以下工作中也不需要装VS。。
很奇怪的是,我的本本装了matlab2007b,自带一个Lcc-win32 C
2.4.1,不能编译cpp文件,但是我的本本是装了VS2010,在matlab命令窗口中输入mex -setup后没有Visual
studio的编译器,我在网上找不到matlab2007b对应的SDK 7.1,用2012b对应的x86版SDK
7.1,半天都没装上编译器。。PS:推荐用高版本的matlab!
于是我就点击
/support/compilers/R2012b/win64.html,并选择下表中第一个编译器进行安装。
在安装SDK界面勾选以下项,并自行安装,安装过程需要个把小时,请耐心等待
安装完毕后,就在matlab的命令窗口里输入以下指令,并选择编译器
这里编译就通过了。。
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

我要回帖

更多关于 matlab2014a编译器 的文章

 

随机推荐