1

The OpenMP website says: "GCC 4.9 supports OpenMP 4.0 for C/C++".

I'm using gcc 4.9.1 from brew, yet I see this error when I try to compile liblinear: omp.h file not found.

Specifically:

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.

Here's the matlab code used to compile liblinear, which contains a file that contains #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`

UPDATE

I changed the gcc version in mexopts.sh (side note: I copied it from /Applications/MATLAB_R2013a_Student.app/bin/mexopts.sh to ~/.matlab/R2013a). Specifically, I changed CC=xcrun -sdk macosx10.9 clang to CC='gcc-4.9'.

I think Matlab does indeed use this compiler, because when I run this code:

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 prints:

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.

Yet when I try to compile liblinear, I get the very same error message as usual.

Rose Perrone
  • 61,572
  • 58
  • 208
  • 243

1 Answers1

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).

Hristo Iliev
  • 72,659
  • 12
  • 135
  • 186
  • Thanks, but I get the same error. I updated the code in the question to show what I executed. Before running the command, `$COMPFLAGS` is empty. – Rose Perrone Nov 04 '14 at 19:45
  • @RosePerrone, I didn't notice initially that the error message is not one that GCC would give. See the newly added part. Basically, you have to change your question to "How do I tell MATLAB to use a different compiler?" – Hristo Iliev Nov 04 '14 at 21:45