简体   繁体   English

无法使用Xcode版本4.3.2在Mac OS X Lion 10.7.5上运行Matlab Mex文件

[英]Cannot run Matlab Mex files on Mac OS X Lion 10.7.5 with Xcode Version 4.3.2

When I am trying to run c++ codes on matlab, I use the following commands: 当我尝试在matlab上运行c ++代码时,我使用以下命令:

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 mex'-setup'(然后选择以下两个选项:1:/Applications/MATLAB_R2011a_Student.app/bin/gccopts.sh:用于构建gcc MEX文件的模板选项文件

and 2: /Applications/MATLAB_R2011a_Student.app/bin/mexopts.sh : Template Options file for building MEX-files via the system ANSI compiler 和2:/Applications/MATLAB_R2011a_Student.app/bin/mexopts.sh:用于通过系统ANSI编译器构建MEX文件的模板选项文件

When I select either one and select a mex file by writing the following:mex mextest1p0.cpp, I get these error messages: 当我选择其中一个并通过编写以下代码来选择一个mex文件时:mex mextest1p0.cpp,我收到以下错误消息:

/Applications/MATLAB_R2011a_Student.app/bin/mex: line 1041: g++-4.2: command not found /Applications/MATLAB_R2011a_Student.app/bin/mex:第1041行:g ++-4.2:未找到命令

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 need to install a compiler -- namely G++ (the GNU C++ compiler). 您需要安装一个编译器-即G ++(GNU C ++编译器)。 On OS X, the easiest way to do is this is by installing the XCode Command Line Developer Tools -- open up XCode, go to preferences, choose downloads, and then install the command line tools. 在OS X上,最简单的方法是安装XCode命令行开发人员工具-打开XCode,转到首选项,选择下载,然后安装命令行工具。 If Matlab still can't find G++, you've got a path problem (and tell us about it) -- the solution is then probably in your gccopts script. 如果Matlab仍然找不到G ++,则说明您遇到了路径问题(并告诉我们有关问题的信息)-解决方案可能就在您的gccopts脚本中。

You don't actually need to install all of Xcode if you don't want to, I believe. 我相信,如果您不需要,实际上不需要安装所有Xcode。 It takes up a lot of hard drive space. 它占用大量硬盘空间。 You will need (1) an Apple Developer account (free for students). 您将需要(1) Apple Developer帐户(学生免费)。 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). 然后,您可以(2)转到位于developer.apple.com下载页面,并仅获取适用于您的OS X版本的命令行工具下载(针对10.7的最新版本是在2013年3月,它位于下载的第三页上)目前)。 Run the installer for this. 为此运行安装程序。

Then you'll need to (3) edit your mexopts.sh file. 然后,您需要(3)编辑mexopts.sh文件。 You'll need to do this if you have Xcode or not. 如果您有Xcode,则需要这样做。 Type the following in your Matlab command window: 在Matlab命令窗口中键入以下内容:

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). 您需要根据系统和命令行工具附带的编译器来编辑文件(您可以尝试通过在Terminal.app中运行cc -vc++ -v或类似版本来获取版本)。 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): 查找与OS X相关的部分。您需要设置以下项目(这些内容来自Matlab R2012b,此后有所更改,但是我想您使用的是旧版本):

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' . 如果您使用的是Xcode,则SDKROOT可能应该为'/Developer/SDKs/MacOSX10.7.sdk' For the C++ section just below you'll probably need 对于下面的C ++部分,您可能需要

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: (4)最后,保存编辑后的mexopts.sh文件,并在Matlab命令窗口中运行以下命令:

mex -setup

Choose your file (press 1 probably) and choose yes ([y]). 选择您的文件(可能按1),然后选择是([y])。 You should now be able to compile using the mex function. 您现在应该可以使用mex函数进行编译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM