GCC C / C ++ MEX Matlab的R2015的Mac OS X(使用OpenMP)不工作 [英] GCC C/C++ MEX Matlab R2015 Mac OS X (with OpenMP) doesn't work
问题描述
我试图编译使用GCC / G ++在Matlab一个非常简单的MEX文件...
首先我检查,这是已经被安装在MATLAB:
!这GCC
输出:
在/ usr /斌/ gcc的...
之后,我试着做到以下几点:
MEX -v GCC ='的/ usr / bin中/海湾合作委员会的hello.c
块引用>
块引用>但它剧照以X code编译锵...
这是使用G ++使用OpenMP库的并行计算。众所周知,并非正式Mathworks公司的支持,但可能的。
解决方案最后,我找到了解决之有道...
首先,mexopts.sh不会在文件夹中默认显示文件,要打开一个终端,寻找它与创建(MATLAB将自动MEX编译时重定向到它):找到〜/ -name'mexopts.sh
和将会出现:
/用户/ FOO //。垃圾桶/ MATLAB_R2014a.app /斌/ mexopts.sh
然后,复制如下:
CP /Users/FOO//.Trash/MATLAB_R2014a.app/bin/mexopts.sh〜/ .matlab / R2014a
然后转到文件夹
CD〜/ .matlab / R2014a
并为您的用户的更改权限:CHMOD U + RWX mexopts.sh
然后,用默认的文本编辑器(推荐崇高文本)为打开:
开放mexopts.sh
和编辑如下:
变化出现在哪里,以macosx10.7当前版本,在我的情况macos10.10
然后,修改以下各行如( http://www.mathworks.com/matlabcentral describen /新闻阅读器/ view_thread / 334250 ):#CC ='xcrun -sdk macosx10.7铛'#OLD
CC ='xcrun在/ usr / local / bin目录/ gcc的'#NEW#CXX ='xcrun -sdk macosx10.7铛++ #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目录> #新
#CXXLIBS =$ MLIBS -lstdc ++#OLD
CXXLIBS =$ MLIBS -lstdc ++ -I在/ usr / local / lib目录-lgomp#NEW注意事项:
请确保您当前的G ++ / G ++ 4.9能够使用OpenMP编译,试图包括< omp.h>
在一个Hello World文件中的命令行做G ++ - 4.9 -o测试HELLO.CPP -fopenmp
或
G ++ -o测试HELLO.CPP -fopenmp
也有可能是一个文件被损坏,有必要做<一href=\"http://stackoverflow.com/questions/26950421/can-not-compile-fortran-because-dyld-library-not-loaded\">Can库未加载:因为dyld的不FORTRAN编译
BREW RM cloog酿造安装cloog
(但是首先检查)...
也有可能是,如果你不能够与OMP编译是必要的,这里描述先做两件事情(<一个href=\"http://stackoverflow.com/questions/29057437/compile-openmp-programs-with-gcc-compiler-on-os-x-yosemite\">Compile与OS X的优胜美地 gcc编译OpenMP程序):
1.有一个新的gcc编译器从 http://hpc.sourceforge.net/
2.将通过$一个新的可执行文件夹sudo的焦油-xvf GCC-4.9-bin.tar -C /
3.切换到它通过出口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屋!