C standard libraries not found when compiling mex files in Matlab

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 enable mex.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 am trying to compile a trivial C file for use in Matlab via mex, but it seems like it never finds the default libraries that I know are installed. For example, trying to compile the following:

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

gives me an error:

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

even if it compiles using gcc. Even worse, when I try to include mex.h as follows:

 #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 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 that mex is not looking for a suitable place for these libraries, or the installation is incorrect, but I have no idea how to fix it.

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

+4
source share
3 answers

The included file should be in your PATH (the type of path to display these folders), unless you specifically include them using mex -Ipathname. You can click "File-> Set Path" and add a folder containing the string.h string.

+1
source

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

+1
source

Set the following parameters with mex and it will work fine. Make sure you have the standard header files in the following folder, otherwise update accordingly:

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

If you overcome this error, it may also be available for .lib. Turn it on similarly

 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
source

Source: https://habr.com/ru/post/1446076/


All Articles