GCC C / C ++ MEX Matlab R2015 Mac OS X(带OpenMP)不工作 [英] GCC C/C++ MEX Matlab R2015 Mac OS X (with OpenMP) doesn't work
问题描述
首先我检查,这已经安装在matlab通过:
!which gcc
输出:
/ usr / bin / gcc ...
之后,我尝试执行以下操作:
$ b b
mex -v GCC ='/ usr / bin / gcc'hello.c
但它仍然使用XCode Clang ...
编译这是使用G ++与OPENMP库进行并行计算。
已知不是由Mathworks支持,而是POSSIBLE。
方式来解决它...
首先,文件mexopts.sh默认情况下不出现在文件夹中,是必要的打开一个终端,并寻找它并创建它(然后Matlab会重定向到它自动用MEX编译):
find〜/ -name'mexopts.sh'
并会显示:
/ Users / FOO //.Trash/MATLAB_R2014a.app/bin/mexopts.sh
然后,将其复制为:/ p>
cp /Users/FOO//.Trash/MATLAB_R2014a.app/bin/mexopts.sh〜/ .matlab / R2014a
然后转到文件夹 cd〜/ .matlab / R2014a
并将您的用户的权限更改为:
chmod u + rwx mexopts.sh
然后,使用默认文本编辑器(推荐Sublime文本)打开它:
打开mexopts.sh
更改在哪里出现macosx10.7到您当前的版本,在我的案例macos10.10
然后,修改以下行描述在( http://www.mathworks.com/matlabcentral/newsreader/view_thread/334250 ):
#CC ='xcrun -sdk macosx10.7 clang'#OLD $ b $ c CC ='xcrun / usr / local / bin / gcc'#NEW
#CXX ='xcrun -sdk macosx10.7 clang ++'#OLD
CXX ='xcrun / usr / local / bin / g ++'#NEW
#CLIBS =$ CLIBS -lstdc ++#OLD
CLIBS =$ CLIBS -lstdc ++ -I / usr / local / lib -lgomp#directory #CXXLIBS =$ MLIBS -lstdc ++#OLD
CXXLIBS =$ MLIBS -lstdc ++ -I / usr / local / lib -lgomp#NEW
重要注意:
确保当前的G ++ / G ++ 4.9能够使用OpenMP进行编译, c $ c>< omp.h> 在命令行中执行的hello world文件中:
g ++ - 4.9 -o test hello.cpp -fopenmp
或
g ++ -o test hello.cpp -fopenmp
也可能是文件已损坏,并且必须执行无法编译fortran因为dyld:库未加载:
brew rm cloog
brew install cloog
(但先检查)...
也有可能,如果你不能编译OMP是必要的做一些事情,如这里描述的(在OS X Yosemite上使用gcc编译器编译OpenMP程序):
1.获得一个新的gcc来自 http://hpc.sourceforge.net/
的编译器2.放置一个新的可执行文件夹$ sudo tar -xvf gcc-4.9-bin.tar -C /
3.通过export切换到PATH = / usr / local / bin:$ PATH
最后,尝试使用以下命令编译您的MEX文件:
mex hello.cpp COMPFLAGS =/ openmp $ COMPFLAGS
这是
...。
I'm trying to compile a very simple MEX file in Matlab using GCC/G++... First I checked that this is already installed in matlab by: !which gcc
output: /usr/bin/gcc ... After, I tried to do the following:
mex -v GCC='/usr/bin/gcc' hello.c
but it stills compiling with XCode Clang... This is to use G++ with OPENMP library for parallel computing.
Is known that is NOT OFFICIALLY Supported by Mathworks, but POSSIBLE.
Finally, I found a proper way to solve it... First, the file mexopts.sh doesn't appear in the folder by default, is necessary to open a terminal and look for it and create it (then Matlab will redirect to it automatically when compiling with MEX):
find ~/ -name 'mexopts.sh'
and will appear:
/Users/FOO//.Trash/MATLAB_R2014a.app/bin/mexopts.sh
Then, copy it as:
cp /Users/FOO//.Trash/MATLAB_R2014a.app/bin/mexopts.sh ~/.matlab/R2014a
then go to the folder cd ~/.matlab/R2014a
and change permissions for your user as:
chmod u+rwx mexopts.sh
then, open it with your default text editor (Sublime text recommended) as:
open mexopts.sh
and edit the following: Change where appears macosx10.7 to your current version, in my case macos10.10 then, modify the following lines as describen in (http://www.mathworks.com/matlabcentral/newsreader/view_thread/334250):
# CC='xcrun -sdk macosx10.7 clang' #OLD
CC='xcrun /usr/local/bin/gcc' #NEW
# CXX='xcrun -sdk macosx10.7 clang++' #OLD
CXX='xcrun /usr/local/bin/g++' #NEW
# CLIBS="$CLIBS -lstdc++" #OLD
CLIBS="$CLIBS -lstdc++ -I/usr/local/lib -lgomp" #directory <-I/usr/local/lib> #NEW
#CXXLIBS="$MLIBS -lstdc++" #OLD
CXXLIBS="$MLIBS -lstdc++ -I/usr/local/lib -lgomp" #NEW
IMPORTANT NOTE:
Make sure that your current G++/G++4.9 is able to compile with OpenMP, trying to include <omp.h>
in a hello world file doing in the command line:
g++-4.9 -o test hello.cpp -fopenmp
or
g++ -o test hello.cpp -fopenmp
is also possible that a file is corrupted and is necessary to do Can not compile fortran because dyld: Library not loaded :
brew rm cloog
brew install cloog
(But check first)...
Is also possible that if you're not able to compile with OMP is necessary to do first a couple of things as described here (Compile OpenMP programs with gcc compiler on OS X Yosemite): 1. Got a new gcc complier from http://hpc.sourceforge.net/ 2. Place a new executable folder by $ sudo tar -xvf gcc-4.9-bin.tar -C / 3. Switched to it by export PATH=/usr/local/bin:$PATH
Finally, try to compile your MEX file with:
mex hello.cpp COMPFLAGS="/openmp $COMPFLAGS"
That's it ... .
这篇关于GCC C / C ++ MEX Matlab R2015 Mac OS X(带OpenMP)不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!