Janne Swaegers
Janne Swaegers

Reputation: 21

omp.h' file not found while compiling source code

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.

Upvotes: 1

Views: 3676

Answers (2)

Janne Swaegers
Janne Swaegers

Reputation: 21

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

Upvotes: 1

user9614249
user9614249

Reputation:

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.

Upvotes: 1

Related Questions