Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

compiler errors - Cannot use HDF5 because it was created by a different version of GNU Fortran

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.

question from:https://stackoverflow.com/questions/65908213/cannot-use-hdf5-because-it-was-created-by-a-different-version-of-gnu-fortran

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...