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.
1
  • 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 <folder> 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. Commented Jan 31, 2021 at 20:12

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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 stackoverflow.com/questions/61843134/…
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.