1

I am trying to compile this this source code (https://sites.google.com/site/bgcsoftware/) on a mac. I installed both hdf5 and gsl using homebrew.

Would you know what the problem might be?

Thank you in advance!

h5c++ -Wall -O2 -o bgc bgc_main.C bgc_func_readdata.C bgc_func_initialize.C bgc_func_mcmc.C bgc_func_write.C bgc_func_linkage.C bgc_func_ngs.C bgc_func_hdf5.C mvrandist.c -lgsl -lm
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
bgc_main.C:17:10: fatal error: 'omp.h' file not found
#include <omp.h>
         ^~~~~~~
1 error generated.
bgc_func_mcmc.C:12:10: fatal error: 'omp.h' file not found
#include <omp.h>
         ^~~~~~~
1 error generated.
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Welcome to SO. You probably need to provide the folder containing `omp.h` as include folder to your compiler. For GCC this is done via `-I ` option. For `h5c++` you need to consult the manual. BTW. If you compile your code as C++, please don't add C language tag. They are different languages. – Gerhardh Jan 31 '21 at 20:12

2 Answers2

1

It looks like clang is the actual compiler being used. When compiling OpenMP with clang you need to pass the -fopenmp flag.

Try adding the -fopenmp flag like this:

h5c++ -fopenmp -Wall -O2 -o bgc \
  bgc_main.C bgc_func_readdata.C bgc_func_initialize.C \
  bgc_func_mcmc.C bgc_func_write.C bgc_func_linkage.C \
  bgc_func_ngs.C bgc_func_hdf5.C mvrandist.c -lgsl -lm

The -fopenmp flag tells the compiler replace the code marked with #pragma omp ... with generated parallel code and should automatically add the correct -I include flags behind the scenes.

You should be able to run

h5c++ --help | grep openmp

To see other openmp related flags, depending on your compiler/OS.

Increasingly Idiotic
  • 5,700
  • 5
  • 35
  • 73
  • 3
    If the clang here is the one from Xcode, it pretends no to understand OpenMP, but you may be ab,e to trick it. See https://stackoverflow.com/questions/61843134/running-openmp-with-different-version-of-g-in-mac – Jim Cownie Feb 01 '21 at 14:48
1

adding -fopenmp did not help. However, the original code did run when I installed: brew install --build-from-source libomp