MATLAB MEX 无法使用 XCode 4.3 (Mac) 找到标准库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9845762/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:46:02  来源:igfitidea点击:

MATLAB MEX can't find standard library with XCode 4.3 (Mac)

xcodematlabmexxcode4.3

提问by Bryan P

I am getting started with using MEX files for MATLAB (R2012a) compiled from C code (using XCode 4.3) on my Mac (running OSX 10.7.3, Lion). I have already installed the MATLAB provided XCode patchwhich configures MATLAB to use the new llvm-gcc compiler under XCode 4.2+, but I am still getting the following error attempting to compile the example file using mex timestwo.c:

我开始在我的 Mac(运行 OSX 10.7.3,Lion)上使用从 C 代码(使用 XCode 4.3)编译的 MATLAB(R2012a)的 MEX 文件。我已经安装了 MATLAB 提供的XCode 补丁,该补丁将 MATLAB 配置为在 XCode 4.2+ 下使用新的 llvm-gcc 编译器,但尝试使用以下命令编译示例文件时仍然出现以下错误mex timestwo.c

/Applications/MATLAB_R2012a.app/extern/include/matrix.h:852:20: error: stdlib.h: No such file or directory
In file included from timestwo.c:1:
/Applications/MATLAB_R2012a.app/extern/include/mex.h:161:19: error: stdio.h: No such file or directory

The compilation then breaks

编译然后中断

mex: compile of ' "timestwo.c"' failed.

Error using mex (line 206)
Unable to complete successfully.

Clearly, the compiler can't find the standard library header directory, but what do I need to change to successfully compile?

显然,编译器找不到标准库头目录,但是我需要更改什么才能成功编译?

回答by Bryan P

Ah, found it!

啊,找到了!

The MATLAB provided template uses /Developer/... for the SDK location, but this changed under XCode4.3 to live under the XCode.app. To fix things, I had to edit my ~/.matlab/R2012a/mexopts.shfile to set the SDKROOT directory to the new location.

MATLAB 提供的模板使用 /Developer/... 作为 SDK 位置,但这在 XCode4.3 下已更改为位于 XCode.app 下。为了解决问题,我必须编辑我的~/.matlab/R2012a/mexopts.sh文件以将 SDKROOT 目录设置为新位置。

To do this, search for SDKROOT in the mexopts.sh file and change it to read:

为此,请在 mexopts.sh 文件中搜索 SDKROOT 并将其更改为:

SDKROOT='/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/'

Note, I chose the 10.7 sdk b/c I am on Lion. Use 10.6 if you are on Snow Leopard

请注意,我在 Lion 上选择了 10.7 sdk b/c。如果您使用的是 Snow Leopard,请使用 10.6

回答by fgar

I am running Mac Mountain Lion and Matlab R2012b, and the following solution worked for me: Matlab 2012a Mex to work with Xcode 4.5 on Mountain Lion

我正在运行 Mac Mountain Lion 和 Matlab R2012b,以下解决方案对我有用Matlab 2012a Mex to work with Xcode 4.5 on Mountain Lion

To be precise, I was getting the following errors:

准确地说,我收到以下错误:

error: stdio.h: No such file or directory

error: stdio.h: No such file or directory

error: stdlib.h: No such file or directory

error: stdlib.h: No such file or directory

error: math.h: No such file or directory

error: math.h: No such file or directory

So what I did to solve this issue:

所以我做了什么来解决这个问题:

I installed Xcode with Command Line Tools, and then edited the file "/Applications/MATLAB_R2012b.app/bin/mexopts.sh" by:

我使用命令行工具安装了 Xcode,然后通过以下方式编辑了文件“/Applications/MATLAB_R2012b.app/bin/mexopts.sh”:

changing CC from gcc-4.2 to llvm-gcc-4.2

将 CC 从 gcc-4.2 更改为 llvm-gcc-4.2

changing CXX from gcc-4.2 to llvm-g++-4.2

将 CXX 从 gcc-4.2 更改为 llvm-g++-4.2

setting SDKROOT to '/'

将 SDKROOT 设置为“/”

Then I ran "mex -setup" in MATLAB, chose number 1, and chose y to overwrite the old /Users/insertyournamehere/.matlab/R2012b/mexopts.sh

然后我在 MATLAB 中运行“mex -setup”,选择数字 1,并选择 y 覆盖旧的 /Users/insertyournamehere/.matlab/R2012b/mexopts.sh

That solved it :)

那解决了它:)

回答by lizzie

You will find valuable information here: http://www.mathworks.fr/support/solutions/en/data/1-FR6LXJ/

您会在这里找到有价值的信息:http: //www.mathworks.fr/support/solutions/en/data/1-FR6LXJ/