4

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:

  1. I open the 'build option' in project in codeblocks. Then I directly jump to linker settings. And add the .a library files that needed.
  2. 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?

3
  • 1
    You need to tell the compiler where to find the HDF5 module. Typically, they reside in the include folder. Locate the module files and add -I/path/to/modules to the compiler options. Commented Jun 22, 2015 at 20:20
  • @AlexanderVogt Thanks for the reply! I added modules files and library files but it turns out to be still ineffective. gfortran -Jobj/Debug/ -Wall -O3 -I/usr/local/hdf5/include -c /home/shawn/Documents/datafile_oldubuntu/Academics/Data_analysis_code/FFT/FFT_spENS/ens.f90 -o obj/Debug/ens.o Commented Jun 29, 2015 at 0:34
  • then I Link : gfortran -o bin/Debug/FFT_spENS obj/Debug/ens.o obj/Debug/fft.o obj/Debug/global.o obj/Debug/main_ens.o /usr/local/hdf5/lib/libhdf5_fortran.a /usr/local/hdf5/lib/libhdf5.a /usr/local/hdf5/lib/libhdf5.a(H5PL.o): In function H5PL_term_interface': H5PL.c:(.text+0xa7): undefined reference to dlclose' so it still wrong somewhere Commented Jun 29, 2015 at 0:35

2 Answers 2

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

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

Comments

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.

enter image description here

7 Comments

Thanks for your help! I figured out the process of compiling and linking.
First is to include the precompiled modules. Second is to link the .o files with library (.a) files, to make a "a.out"
But I still cannot make it... please see: then I Link : gfortran -o bin/Debug/FFT_spENS obj/Debug/ens.o obj/Debug/fft.o obj/Debug/global.o obj/Debug/main_ens.o /usr/local/hdf5/lib/libhdf5_fortran.a /usr/local/hdf5/lib/libhdf5.a /usr/local/hdf5/lib/libhdf5.a(H5PL.o): In function H5PL_term_interface': H5PL.c:(.text+0xa7): undefined reference to dlclose' so it still wrong somewhere
@PabPeter you are probably still just missing library references. If by "HDF5 official modified version of gfortran" you just mean h5cc or similar, that is just a shell script that adds arguments to the command line. You can see what options it will use with h5cc -show.
I made it! Thank you!! Solution: I h5fc -show. then comes out: gfortran -I/usr/local/hdf5/include -L/usr/local/hdf5/lib /usr/local/hdf5/lib/libhdf5hl_fortran.a /usr/local/hdf5/lib/libhdf5_hl.a /usr/local/hdf5/lib/libhdf5_fortran.a /usr/local/hdf5/lib/libhdf5.a -L/usr/local/hdf5/lib -ldl -lm -Wl,-rpath -Wl,/usr/local/hdf5/lib then I put them into both linker commands and compiler commands inside Codeblocks. A few warnings but everything is perfect! Now I can do whatever I want!
|

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.