0

I'm quite new to both HDF5 as well as Fortran 90. I am trying to compile a program which runs fine without HDF5. I found online that I need to use flags from the command h5fc -show, and the output is like such

x86_64-conda_cos6-linux-gnu-gfortran -I/home/tmph/anaconda3/include -L/home/tmph/anaconda3/lib /home/tmph/anaconda3/lib/libhdf5hl_fortran.a /home/tmph/anaconda3/lib/libhdf5_hl.a /home/tmph/anaconda3/lib/libhdf5_fortran.a /home/tmph/anaconda3/lib/libhdf5.a -L/home/tmph/anaconda3/lib -Wl,-O2 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro -Wl,-z,now -Wl,--disable-new-dtags -Wl,-rpath,/home/tmph/anaconda3/lib -L/home/tmph/anaconda3/lib -lrt -lpthread -lz -ldl -lm -Wl,-rpath -Wl,/home/tmph/anaconda3/lib

(Most of my day-to-day work is actually in Python, hence anaconda3)

I try to compile with

[...]
LDLIBS=-lhdf5_fortran -lhdf5 
LDINC=-I/home/tmph/anaconda3/include
LDFLAGS=-L/home/tmph/anaconda3/lib

$(OBJ_DIR)%.o: $(SRC_DIR)%.F90
    $(FC) $(FCFLAGS) $(LDINC) -c $< -J $(SRC_DIR) -o $@

exec: $(SOURCE_OBJECTS) $(MAIN_OBJECT)
    $(LC) $(FCFLAGS) $(LDINC) -o $(exec_name) $^ $(LDFLAGS) $(LDLIBS)

but I am met with the error

12 | use HDF5 | 1 Fatal Error: Cannot read module file ‘/home/tmph/anaconda3/include/hdf5.mod’ opened at (1), because it was created by a different version of GNU Fortran compilation terminated.

When I run gfortran --version I get the output

GNU Fortran (GCC) 10.2.0 Copyright (C) 2020 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

but I don't know how to check what version was used for the hdf5.mod file in anaconda. Is it a problem with the fact that it is from Anaconda? Need I install another one? If so, how? Must I rebuild the module somehow (and would this mess up some python packages)? Perhaps I need to use more of the flags? (I used the ones I thought made sense and was similar to makefiles I found on github, this one for example)

I also tried modifying an example Makefile, but I have no such libz.a or libsz.a that I know of, and in the end I get the same error.

I am running Manjaro, in case that matters. I also tried installing HDF5 with pacman -S hdf5, which works but didn't change anything.

Edit: it turns out when you install Anaconda, it adds acanconda3/bin to the front of the path. This contained an outdated version of h5fc, which is where the confusion came from. If I use the output from /usr/bin/h5fc, then the compilation runs without any problems.

2 Answers 2

-1

Flags will not solve this. You need to use the same version of gfortran for all modules in the program. If you want to keep your version oh HFD, you need to get the same gfortran version.

You can find out the gfortran version of the .mod file by reading the first lines of the file and reading the module number. Then you can proceed to the table here Is it possible to determine which Fortran compiler generated a ".mod" file?

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

1 Comment

Using gunzip on the mod file as matthieu suggested, I found that the module corresponds to gfortran 5.1.0 (if I read correctly: module version 14), which couldn't be right because both anaconda and HDF5 were reinstalled in the last week. Turns out the new version was installed in /usr/include, but anaconda3 is earlier in my path so h5fc was called from there. Using the hdf5 module inside /usr/include, everything works fine without needing to change compilers.
-1

Though my solution is a bit generic, I'm writing this here because I faced a similar issue and couldn't find a solution quickly with HDF5 installation and a Fortran version mismatch.

Doing make clean && make distclean and autoreconf -ivf did the trick for me.

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.