无法在Mac OS X Lion 10.7.5上使用Xcode版本4.3.2运行Matlab Mex文件 [英] Cannot run Matlab Mex files on Mac OS X Lion 10.7.5 with Xcode Version 4.3.2

查看:619
本文介绍了无法在Mac OS X Lion 10.7.5上使用Xcode版本4.3.2运行Matlab Mex文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在matlab上运行c ++代码时,我使用以下命令:



mex'-setup'
两个选项是:
1:/Applications/MATLAB_R2011a_Student.app/bin/gccopts.sh:
用于构建gcc MEX文件的模板选项文件




2:/Applications/MATLAB_R2011a_Student.app/bin/mexopts.sh:
用于通过系统ANSI编译器构建MEX文件的模板选项文件



当我选择一个并选择一个mex文件通过写入以下:mex mextest1p0.cpp,我得到这些错误消息:



/应用程序/ MATLAB_R2011a_Student。 app / bin / mex:line 1041:g ++ - 4.2:command not found



如何解决这个问题注意:已经尝试过各种解决方案,但没有什么工作

解决方案

你不需要安装所有的Xcode,我想,我相信它占用了很多硬盘空间。您需要(1)一个Apple开发人员帐户(学生可免费使用)。然后,您可以(2)转到developerWorks上的下载页面。 com ,并得到您的OS X版本的命令行工具下载(最后的10.7是在2013年3月 - 它在目前的第三页下载)。



然后您需要(3)编辑您的 mexopts.sh code>文件。如果你有Xcode,你需要这样做。在Matlab命令窗口中键入以下内容:

  edit([matlabroot'/bin/mexopts.sh'])

复制打开的文件,以防万一。您需要根据您的系统和命令行工具中包含的编译器来编辑文件(您可以尝试通过运行 cc -v c ++ -v 或类似于Terminal.app)。查找与OS X相关的部分。您需要设置以下项目(这些是来自Matlab R2012b,并且稍微改变,但我猜你正在使用旧版本):

  CC ='llvm-gcc-4.2'


b $ b

或者只是

  CC ='gcc-4.2'

  SDKROOT ='/'
MACOSX_DEPLOYMENT_TARGET = '10 .7'

如果使用Xcode, SDKROOT 应该应该'/ Developer / SDKs / MacOSX10.7.sdk'。对于下面的C ++部分,您可能需要

  CXX ='llvm-g ++  -  4.2'

  CXX = 'g ++  -  4.2'

(4) code> mexopts.sh 文件并在Matlab命令窗口中运行以下命令:

 选择您的文件(可能按1),然后选择yes([y])。您现在应该可以使用 mex 函数进行编译。


When I am trying to run c++ codes on matlab, I use the following commands:

mex '-setup' (Then I select the following two options which are: 1: /Applications/MATLAB_R2011a_Student.app/bin/gccopts.sh : Template Options file for building gcc MEX-files

and 2: /Applications/MATLAB_R2011a_Student.app/bin/mexopts.sh : Template Options file for building MEX-files via the system ANSI compiler

When I select either one and select a mex file by writing the following:mex mextest1p0.cpp, I get these error messages:

/Applications/MATLAB_R2011a_Student.app/bin/mex: line 1041: g++-4.2: command not found

How can I fix this. Note: I have seen a couple post about this problem and I've tried various solutions, but nothing is working

解决方案

You don't actually need to install all of Xcode if you don't want to, I believe. It takes up a lot of hard drive space. You will need (1) an Apple Developer account (free for students). You can then (2) go to the downloads page at developer.apple.com and get just the Command Line Tools download for your version of OS X (the last to these for 10.7 was in March 2013 – it's on the third page of downloads currently). Run the installer for this.

Then you'll need to (3) edit your mexopts.sh file. You'll need to do this if you have Xcode or not. Type the following in your Matlab command window:

edit([matlabroot '/bin/mexopts.sh'])

Make a copy of the file that opens in case you screw up. You'll need to edit the file based on your system and the complier included with the Command Line Tools (you can try getting the versions by running cc -v and c++ -v or similar in Terminal.app). Look for the section related to OS X. You'll need to set the following items (these are from Matlab R2012b and have changed slightly since, but I'm guessing you're using an older version):

CC='llvm-gcc-4.2'

or maybe just

CC='gcc-4.2'

and

SDKROOT='/'
MACOSX_DEPLOYMENT_TARGET='10.7'

If you're using Xcode, the SDKROOT should probably be '/Developer/SDKs/MacOSX10.7.sdk'. For the C++ section just below you'll probably need

CXX='llvm-g++-4.2'

or

CXX='g++-4.2'

(4) Finally, save your edited mexopts.sh file and run the following in the Matlab command window:

mex -setup

Choose your file (press 1 probably) and choose yes ([y]). You should now be able to compile using the mex function.

这篇关于无法在Mac OS X Lion 10.7.5上使用Xcode版本4.3.2运行Matlab Mex文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆