2014-11-03 59 views
1

OpenMP網站上說:「GCC 4.9支持C/C++的OpenMP 4.0」。OpenMP不適用於使用gcc的mac 4.9

我從brew中使用gcc 4.9.1,但是當我嘗試編譯liblinear時發現這個錯誤:omp.h file not found

具體做法是:

Compiling liblinear version 1.93 
Source code page: 
    http://www.csie.ntu.edu.tw/~cjlin/liblinear/ 
external/liblinear-1.93_multicore/matlab/train.cpp:7:10: fatal error: 'omp.h' file not found 
#include <omp.h> 
     ^
1 error generated. 

    mex: compile of ' "external/liblinear-1.93_multicore/matlab/train.cpp"' failed. 

下面是用來編譯liblinear的MATLAB代碼,其中包含帶有#include <omp.h>文件:

我改變了gcc版本

% Compile liblinear 
if ~exist('liblinear_train') 
    fprintf('Compiling liblinear version 1.93\n'); 
    fprintf('Source code page:\n'); 
    fprintf(' http://www.csie.ntu.edu.tw/~cjlin/liblinear/\n'); 

    mex -outdir bin ... 
     COMPFLAGS="$COMPFLAGS -fopenmp" -largeArrayDims ... 
     external/liblinear-1.93_multicore/matlab/train.cpp ... 
     external/liblinear-1.93_multicore/matlab/linear_model_matlab.cpp ... 
     external/liblinear-1.93_multicore/linear.cpp ... 
     external/liblinear-1.93_multicore/tron.cpp ... 
     "external/liblinear-1.93_multicore/blas/*.c" ... 
     -output liblinear_train; 
end` 

UPDATE mexopts.sh(旁註:我將它從/Applications/MATLAB_R2013a_Student.app/bin/mexopts.sh複製到~/.matlab/R2013a)。具體來說,我將CC=xcrun -sdk macosx10.9 clang更改爲CC='gcc-4.9'

我覺得Matlab的確實使用該編譯器,因爲當我運行此代碼:

if ~exist('anigauss') 
    fprintf('Compiling the anisotropic gauss filtering of:\n'); 
    fprintf(' J. Geusebroek, A. Smeulders, and J. van de Weijer\n'); 
    fprintf(' Fast anisotropic gauss filtering\n'); 
    fprintf(' IEEE Transactions on Image Processing, 2003\n'); 
    fprintf('Source code/Project page:\n'); 
    fprintf(' http://staff.science.uva.nl/~mark/downloads.html#anigauss\n\n'); 
    mex -Dchar16_t=uint16_T -outdir bin ... 
     selective_search/SelectiveSearchCodeIJCV/Dependencies/anigaussm/anigauss_mex.c ... 
     selective_search/SelectiveSearchCodeIJCV/Dependencies/anigaussm/anigauss.c ... 
     -output anigauss 
end 

Matlab的打印:當我嘗試編譯liblinear

dyld: Library not loaded: /usr/local/opt/mpfr2/lib/libmpfr.1.dylib 
    Referenced from: /usr/local/Cellar/gcc49/4.9.1/libexec/gcc/x86_64-apple-darwin14.0.0/4.9.1/cc1 
    Reason: Incompatible library version: cc1 requires version 4.0.0 or later, but libmpfr.1.dylib provides version 3.0.0 
gcc-4.9: internal compiler error: Trace/BPT trap: 5 (program cc1) 
/Applications/MATLAB_R2013a_Student.app/bin/mex: line 1343: 77128 Abort trap: 6   gcc-4.9 -c -I/Applications/MATLAB_R2013a_Student.app/extern/include -I/Applications/MATLAB_R2013a_Student.app/simulink/include -DMATLAB_MEX_FILE -fno-common -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -mmacosx-version-min=10.9 -fexceptions -Dchar16_t=uint16_T -DMX_COMPAT_32 -O2 -DNDEBUG "selective_search/SelectiveSearchCodeIJCV/Dependencies/anigaussm/anigauss_mex.c" -o bin/anigauss_mex.o 

    mex: compile of ' "selective_search/SelectiveSearchCodeIJCV/Dependencies/anigaussm/anigauss_mex.c"' failed. 

然而,我得到了同樣的錯誤信息照常。

+0

你想用什麼命令來編譯? – 2014-11-03 22:51:44

+0

我試圖使用SPP_net,這取決於liblinear。見https://github.com/ShaoqingRen/SPP_net。它是用於圖像中物體檢測的神經網絡。 – 2014-11-03 23:02:56

+0

那是'gcc -I? -L?如何誰在哪裏? – 2014-11-03 23:05:19

回答

2
COMPFLAGS="$COMPFLAGS /openmp" -largeArrayDims ... 
         ^^^^^^^ 

這可能是爲Microsoft Visual C/C++或Windows上的Intel C/C++ Compiler編寫的。 Unix系統(包括OS X)傳統上使用-來表示命令行標誌。

要在GCC中啓用OpenMP支持,您應該在編譯器標誌COMPFLAGS中將/openmp更改爲-fopenmp


看來,除了傳遞了錯誤的OpenMP的標誌,mex使用錯誤的編譯器。從GCC和Clang的比較錯誤輸出:

GCC

foo.c:1:25: fatal error: nonexistent.h: No such file or directory 
#include <nonexistent.h> 
         ^
compilation terminated. 

foo.c:1:10: fatal error: 'nonexistent.h' file not found 
#include <nonexistent.h> 
     ^
1 error generated. 

鐺,或者至少是蘋果自帶的Xcode,不支持OpenMP的版本。請查閱關於如何選擇不同編譯器的mex命令的MATLAB文檔。基本上,你必須執行:

mex -setup 

如果MATLAB檢測到幾個可用的編譯器,它應該爲您提供選擇其中之一的能力。不幸的是,根據this table,MATLAB可能不支持OS X上的GCC(至少它沒有在表中列出)。

+0

謝謝,但我得到同樣的錯誤。我更新了問題中的代碼以顯示我執行的內容。在運行命令之前,'$ COMPFLAGS'是空的。 – 2014-11-04 19:45:20

+0

@RosePerrone,我最初沒有注意到錯誤信息不是GCC會給的。看到新添加的部分。基本上,你必須將你的問題改爲「我如何告訴MATLAB使用不同的編譯器?」 – 2014-11-04 21:45:30