1

OpenMP 网站说:“GCC 4.9 支持 C/C++ 的 OpenMP 4.0”。

我正在使用 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>

% 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`

更新

我在 mexopts.sh 中更改了 gcc 版本(旁注:我将它从复制/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 打印:

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.

然而,当我尝试编译 liblinear 时,我得到了与往常一样的错误消息。

4

1 回答 1

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

This was probably written for Microsoft Visual C/C++ or for Intel C/C++ Compiler on Windows. Unix systems, including OS X, traditionally use - to denote command line flags.

To enable OpenMP support in GCC you should change /openmp to -fopenmp in the compiler flags COMPFLAGS.


It appears that in addition to passing the wrong OpenMP flag, mex is using the wrong compiler. Compare the error outputs from GCC and Clang:

GCC

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

Clang

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

Clang, or at least the version that Apple ships with Xcode, does not support OpenMP. Consult the MATLAB documentation of the mex command on how to select a different compiler. Basically, you have to execute:

mex -setup

If MATLAB detects several usable compilers, it should present you with the ability to pick one of them. Unfortunately, according to this table, MATLAB might not support GCC on OS X (at least it is not listed in the table).

于 2014-11-04T07:33:02.573 回答