How to configure the mexopts.sh file in MAC 10.12.6 El Capitan

1 次查看(过去 30 天)
I could not compile the c code in MATLAB 2012b on my MAC 10.12.6. When I implement the command: mex hello.c, it releases an error like:
gcc-5.3.0: command not found.
I had tried many ways to fix that problem but I failed. I have known that gcc (version 5.3.0) is existed on my MAC, but it seems to me that the MATLAB couldn't link to the gcc. I guess that the configuration in the mexopts.sh is wrong. Below is a part of the mexopts.sh file:
C='gcc-5.3.0'
SDKROOT='Applications/Xcode/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk'
MACOSX_DEPLOYMENT_TARGET='10.5'
ARCHS='x86_64'
CFLAGS="-fno-common -no-cpp-precomp -arch $ARCHS -isysroot $SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
CFLAGS="$CFLAGS -fexceptions"
CLIBS="$MLIBS"
COPTIMFLAGS='-O2 -DNDEBUG'
CDEBUGFLAGS='-g'
#
CLIBS="$CLIBS -lstdc++"
# C++keyName: GNU C++
# C++keyManufacturer: GNU
# C++keyLanguage: C++
# C++keyVersion:
# C++keyLinkerName:
# C++keyLinkerVersion:
CXX=g++-5.3.0
CXXFLAGS="-fno-common -no-cpp-precomp -fexceptions -arch $ARCHS -isysroot $SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
CXXLIBS="$MLIBS -lstdc++"
CXXOPTIMFLAGS='-O2 -DNDEBUG'
CXXDEBUGFLAGS='-g'
Could anyone please let me know how to solve that problem. Thank you!

回答(1 个)

Walter Roberson
Walter Roberson 2016-12-22
Your gcc-5.3 is probably not on your path. If you are calling mex from within MATLAB then first set the PATH environment variable to include the directory that your gcc-5.3 is in. For example,
setenv('PATH', strcat(getenv('PATH'), ':/usr/local/bin'))
  9 个评论
Walter Roberson
Walter Roberson 2017-1-13
Did you install XCode? If you did, then which version?
In mexopts.sh you can change
CC = gcc-5.3
to
CC = /usr/local/bin/gcc-5.3
Marsge
Marsge 2017-1-17
My Xcode version is 8.1 (Build version 8B62). Hi Walter, When I try to specify CC='/usr/local/bin/gcc' (because there is no gcc-5.3 file in the gcc folder), it release another error:
gcc: error: unrecognized command line option '-no-cpp-precomp'

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Write C++ Functions Callable from MATLAB (MEX Files) 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by