问题
I had 11 files that all need HDF5 library. Usually I just use another way to compile and built that program. Now I change my mind and I want to do it myself using Codeblocks.
Here is the problem:
- I open the 'build option' in project in codeblocks. Then I directly jump to linker settings. And add the .a library files that needed.
- Then I just click 'rebuild workspace'.
Here the error messages come out:
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 a thing called hdf5.mod
locally in my compiling folder. So it means that the linker option in codeblocks is not working. Why?
回答1:
The dependency hdf5.mod
is needed at compile time, not link time, which is why you are not having success fixing it via linker options. Module files are somewhat conceptually like C include files (though very different in implementation and not portable). To allow the compiler to find them you pass a search path via a -I
option.
In codeblocks you should find a search directories
tab right next to the linker options you are messing with (In the project build options). In the search directory tab you'll want to select the compiler tab and then add the path to the hdf5 module file.

回答2:
Also make sure you have installed the serial hdf5 library package. This may help someone else in the future.
On Ubuntu:
sudo apt-get install libhdf5-serial-dev
I received the same error as you because I only had the MPI versions (libhdf5-openmpi-dev
or libhdf5-mpich-dev
)
On MacOS:
You may need some/all of these flags for Fortran:
brew install homebrew/science/hdf5 --with-fortran --with-mpi --with-fortran2003
来源:https://stackoverflow.com/questions/30986415/how-to-compile-a-program-that-need-hdf5-library-using-codeblocks