在Matlab中编译mex文件时没有发现标准C库。

时间:2022-09-06 15:10:09

Update: I installed XCode and changed SDKROOT in mexopts.sh to reflect the actual path as described here, but I still get this error when I include mex.h:

更新:我安装了XCode,并更改了在美克斯的SDKROOT。sh反映了这里所描述的实际路径,但是当我包含了m .h时,仍然会得到这个错误。

In file included from /Applications/MATLAB_R2012b.app/extern/include/matrix.h:294,
                 from /Applications/MATLAB_R2012b.app/extern/include/mex.h:58,
                 from test.c:2:
/Applications/MATLAB_R2012b.app/extern/include/tmwtypes.h:61:21: error: float.h: No such file or directory

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

I'm trying to compile a trivial C file for use in Matlab through mex, but it seems to never find default libraries that I know are installed. For instance, trying to compile the following:

我正在尝试编译一个简单的C文件,在Matlab中通过mex来使用,但它似乎从来没有找到我所知道的默认库。例如,尝试编译以下内容:

#include <string.h>
int main() {
    return 0;
}

gives me the error:

给我的错误:

test.c:1:20: error: string.h: No such file or directory
mex: compile of ' "test.c"' failed.

even though it compiles fine using gcc. Worse, when I try to include mex.h like so:

即使它使用gcc来编译。更糟的是,当我试着把mex包括进来。h一样:

#include "mex.h"
int main() {
    return 0;
}

I get the following error:

我得到了以下错误:

In file included from /Applications/MATLAB_R2012b.app/extern/include/mex.h:58,
                 from test.c:2:
/Applications/MATLAB_R2012b.app/extern/include/matrix.h:293:20: error: stddef.h: No such file or directory
In file included from /Applications/MATLAB_R2012b.app/extern/include/matrix.h:294,
                 from /Applications/MATLAB_R2012b.app/extern/include/mex.h:58,
                 from test.c:2:
/Applications/MATLAB_R2012b.app/extern/include/tmwtypes.h:43:20: error: limits.h: No such file or directory
/Applications/MATLAB_R2012b.app/extern/include/tmwtypes.h:46:21: error: stdbool.h: No such file or directory
/Applications/MATLAB_R2012b.app/extern/include/tmwtypes.h:61:21: error: float.h: No such file or directory
/Applications/MATLAB_R2012b.app/extern/include/tmwtypes.h:777:2: error: #error "This code must be compiled using a 2's complement representation for signed integer values"
In file included from /Applications/MATLAB_R2012b.app/extern/include/matrix.h:294,
                 from /Applications/MATLAB_R2012b.app/extern/include/mex.h:58,
                 from test.c:2:
/Applications/MATLAB_R2012b.app/extern/include/tmwtypes.h:823: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'CHAR16_T'
In file included from /Applications/MATLAB_R2012b.app/extern/include/mex.h:58,
                 from test.c:2:
/Applications/MATLAB_R2012b.app/extern/include/matrix.h:319: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'mxChar'
/Applications/MATLAB_R2012b.app/extern/include/matrix.h:375: error: expected ')' before 'n'
/Applications/MATLAB_R2012b.app/extern/include/matrix.h:383: error: expected ')' before 'n'
/Applications/MATLAB_R2012b.app/extern/include/matrix.h:397: error: expected declaration specifiers or '...' before 'size_t'
/Applications/MATLAB_R2012b.app/extern/include/matrix.h:590: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'mxGetNumberOfElements'
/Applications/MATLAB_R2012b.app/extern/include/matrix.h:632: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
/Applications/MATLAB_R2012b.app/extern/include/matrix.h:688: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'mxGetM'
/Applications/MATLAB_R2012b.app/extern/include/matrix.h:700: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'mxGetN'
/Applications/MATLAB_R2012b.app/extern/include/matrix.h:750: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'mxGetElementSize'
In file included from /Applications/MATLAB_R2012b.app/extern/include/mex.h:58,
             from test.c:2:
/Applications/MATLAB_R2012b.app/extern/include/matrix.h:851:20: error: stdlib.h: No such file or directory
/Applications/MATLAB_R2012b.app/extern/include/matrix.h:1072: error: expected ')' before 'm'
In file included from test.c:2:
/Applications/MATLAB_R2012b.app/extern/include/mex.h:91: error: expected specifier-qualifier-list before 'size_t'
In file included from test.c:2:
/Applications/MATLAB_R2012b.app/extern/include/mex.h:161:19: error: stdio.h: No such file or directory

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

I assume mex isn't looking in the right place for these libraries, or the installation is corrupt somehow, but I have no idea how to fix it.

我认为,mex没有在正确的地方寻找这些库,或者安装是腐败的,但是我不知道如何修复它。

Mac OSX Mountain Lion + XCode 4.5.2, Matlab R2012b, gcc 4.2.1

Mac OSX Mountain Lion + XCode 4.5.2, Matlab R2012b, gcc 4.2.1。

3 个解决方案

#1


1  

The include file(s) need to be in your PATH (type path to show these folders) unless you specifically include them using mex -Ipathname. You can click 'File->Set Path' and add the folder containing your string.h.

包含文件(s)需要在您的路径中(显示这些文件夹的类型路径),除非您特别使用mex -Ipathname。您可以单击“File->设置路径”并添加包含您的字符串的文件夹。

#2


1  

Just to share, I had similar problem. I was running same version of Matlab and was looking at this page and could not find the answer. I found my answer here: Matlab 2012a Mex to work with Xcode 4.5 on Mountain Lion

为了分享,我遇到了类似的问题。我运行的是同一个版本的Matlab,正在看这个页面,却找不到答案。我在这里找到了我的答案:Matlab 2012a,在Mountain Lion上与Xcode 4.5合作。

#3


1  

Specify the following options with the mex command and it will work fine. Please be sure you have standard header files in the following folder, otherwise update accordingly:

使用mex命令指定以下选项,它将正常工作。请确保您在以下文件夹中有标准的头文件,否则将相应更新:

mex -I'C:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt'.

If you get past this error, it might crib for .lib also. Include that similarly

如果您克服了这个错误,它可能还会为。lib。lib。包括同样

mex -I'C:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt' -L'C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10150.0\ucrt\x64'

#1


1  

The include file(s) need to be in your PATH (type path to show these folders) unless you specifically include them using mex -Ipathname. You can click 'File->Set Path' and add the folder containing your string.h.

包含文件(s)需要在您的路径中(显示这些文件夹的类型路径),除非您特别使用mex -Ipathname。您可以单击“File->设置路径”并添加包含您的字符串的文件夹。

#2


1  

Just to share, I had similar problem. I was running same version of Matlab and was looking at this page and could not find the answer. I found my answer here: Matlab 2012a Mex to work with Xcode 4.5 on Mountain Lion

为了分享,我遇到了类似的问题。我运行的是同一个版本的Matlab,正在看这个页面,却找不到答案。我在这里找到了我的答案:Matlab 2012a,在Mountain Lion上与Xcode 4.5合作。

#3


1  

Specify the following options with the mex command and it will work fine. Please be sure you have standard header files in the following folder, otherwise update accordingly:

使用mex命令指定以下选项,它将正常工作。请确保您在以下文件夹中有标准的头文件,否则将相应更新:

mex -I'C:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt'.

If you get past this error, it might crib for .lib also. Include that similarly

如果您克服了这个错误,它可能还会为。lib。lib。包括同样

mex -I'C:\Program Files (x86)\Windows Kits\10\Include\10.0.10150.0\ucrt' -L'C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10150.0\ucrt\x64'