How do I compile a program that needs HDF5 library (using Codeblocks)?

I had 11 files that need HDF5 library. I usually just use a different way to compile and build this program. Now I change my mind and I want to do it myself using Codeblocks.

Here's the problem:

  • I open the "build option" in the project in code blocks. Then I go straight to the linker settings. And add the required library files .a.
  • Then I just click "rebuild workspace".

Here's where the error messages go:

gfortran -Jobj/Debug/ -Wall  -g  -O3    -c "/home/shawn/Documents/datafile_oldubuntu/Academics/Data_analysis_code/Helmholtz decomposition+rotcombudget/code_budget/budget_helmholtz_comrot_ver2.0_symmertic/global.f90" -o obj/Debug/global.o

/home/shawn/Documents/datafile_oldubuntu/Academics/Data_analysis_code/Helmholtz decomposition+rotcombudget/code_budget/budget_helmholtz_comrot_ver2.0_symmertic/global.f90:3.4:

USE HDF5
    1

Fatal Error: Can't open module file 'hdf5.mod' for reading at (1): No such file or directory
Process terminated with status 1 (0 minute(s), 1 second(s))
1 error(s), 0 warning(s) (0 minute(s), 1 second(s))

      

As you can see, there is no such thing in my compile folder called hdf5.mod

locally. So this means the linker option in codeblocks does not work. Why?

+3


source to share


2 answers


The dependency hdf5.mod

is required at compile time, not link time, so you have no success fixing it with linker options. Module files are somewhat conceptually similar to C include files (although they are very different in implementation and not portable). To let the compiler find them, you step the search path through the option -I

.

In the codeblocks, you should find a tab search directories

next to the linker options you are encountering (in the project build options). In the search directory tab, you have to select the compiler tab and then add the path to the hdf5 module file.



enter image description here

+1


source


Also make sure you have installed the serial hdf5 library package . It might help someone else in the future.

On Ubuntu:

sudo apt-get install libhdf5-serial-dev

I got the same error as you because I only had MPI versions ( libhdf5-openmpi-dev

or libhdf5-mpich-dev

)



On macOS:

You may need several / all of these flags for Fortran:

brew install homebrew/science/hdf5 --with-fortran --with-mpi --with-fortran2003

+1


source







All Articles