I am trying ti build HDF5 1.10.2 with pgfortran 18.4:
export CPP=cpp
export FC=pgfortran
./configure --prefix=/usr/local/hdf5 --disable-shared --enable-fortran
Make ends with an error:
Makefile:967: recipe for target ‘t.lo’ failed
make[2]: *** [t.lo] Error 1
make[2]: Leaving directory ‘/usr/local/src/hdf5-1.10.2/fortran/test’
Makefile:812: recipe for target ‘all-recursive’ failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory ‘/usr/local/src/hdf5-1.10.2/fortran’
Makefile:652: recipe for target ‘all-recursive’ failed
make: *** [all-recursive] Error 1
^
t.h:32:20: note: in expansion of macro ‘nh5_cleanup_c’
H5_FCTESTDLL int_f nh5_cleanup_c
^
t.h:24:39: note: previous declaration of ‘H5_FC_FUNC_’ was here
^
t.h:29:20: note: in expansion of macro ‘nh5_fixname_c’
H5_FCTESTDLL int_f nh5_fixname_c
^
t.h:26:39: error: ‘H5_FC_FUNC_’ declared as function returning a function
^
t.h:35:36: note: in expansion of macro ‘nh5_exit_c’
H5_FCTESTDLL H5_ATTR_NORETURN void nh5_exit_c
^
t.h:25:39: note: previous declaration of ‘H5_FC_FUNC_’ was here
^
t.h:32:20: note: in expansion of macro ‘nh5_cleanup_c’
H5_FCTESTDLL int_f nh5_cleanup_c
^
t.h:27:39: error: ‘H5_FC_FUNC_’ declared as function returning a function
^
t.h:38:19: note: in expansion of macro ‘nh5_env_nocleanup_c’
H5_FCTESTDLL void nh5_env_nocleanup_c
^
t.h:26:39: note: previous declaration of ‘H5_FC_FUNC_’ was here
^
t.h:35:36: note: in expansion of macro ‘nh5_exit_c’
H5_FCTESTDLL H5_ATTR_NORETURN void nh5_exit_c
^
t.h:24:39: error: ‘H5_FC_FUNC_’ declared as function returning a function
^
t.c:43:1: note: in expansion of macro ‘nh5_fixname_c’
nh5_fixname_c(_fcd base_name, size_t_f base_namelen, hid_t_f fapl, _fcd full_name, size_t_f *full_namelen)
^
t.c:52:53: error: ‘base_name’ undeclared (first use in this function)
if(NULL == (c_base_name = (char *)HD5f2cstring(base_name, (size_t)*base_namelen)))
^
t.c:52:53: note: each undeclared identifier is reported only once for each function it appears in
t.c:52:73: error: ‘base_namelen’ undeclared (first use in this function)
if(NULL == (c_base_name = (char *)HD5f2cstring(base_name, (size_t)*base_namelen)))
^
In file included from t.h:15:0,
from t.c:26:
t.c:54:58: error: ‘full_namelen’ undeclared (first use in this function)
if(NULL == (c_full_name = (char *)HDmalloc((size_t)*full_namelen + 1)))
^
../../src/H5private.h:1079:35: note: in definition of macro ‘HDmalloc’ define HDmalloc(Z) malloc(Z)
^
t.c:60:49: error: ‘fapl’ undeclared (first use in this function)
if(NULL == h5_fixname(c_base_name, (hid_t)*fapl, c_full_name, (size_t)*full_namelen + 1))
^
In file included from t.h:16:0,
from t.c:26:
t.c:62:43: error: ‘full_name’ undeclared (first use in this function)
HD5packFstring(c_full_name, _fcdtocp(full_name), (size_t)*full_namelen);
^
../src/H5f90i.h:27:25: note: in definition of macro ‘_fcdtocp’ define _fcdtocp(desc) (desc)
^
t.c:70:13: warning: function declared ‘noreturn’ has a ‘return’ statement
return ret_value;
^
In file included from t.c:26:0:
t.h:24:39: warning: unused parameter ‘h5_fixname_c’ [-Wunused-parameter]
^
t.c:43:1: note: in expansion of macro ‘nh5_fixname_c’
nh5_fixname_c(_fcd base_name, size_t_f base_namelen, hid_t_f fapl, _fcd full_name, size_t_f *full_namelen)
^
t.c: At top level:
t.h:25:39: error: ‘H5_FC_FUNC_’ declared as function returning a function
^
t.c:85:1: note: in expansion of macro ‘nh5_cleanup_c’
nh5_cleanup_c(_fcd base_name, size_t_f base_namelen, hid_t_f fapl)
^
t.h:24:39: note: previous definition of ‘H5_FC_FUNC_’ was here
^
t.c:85:1: note: in expansion of macro ‘nh5_cleanup_c’
nh5_cleanup_c(_fcd base_name, size_t_f base_namelen, hid_t_f fapl)
^
t.h:25:39: warning: type of ‘h5_cleanup_c’ defaults to ‘int’ [-Wimplicit-int]
^
t.c:85:1: note: in expansion of macro ‘nh5_cleanup_c’
nh5_cleanup_c(_fcd base_name, size_t_f base_namelen, hid_t_f fapl)
^
t.h:25:39: warning: type of ‘H5_CLEANUP_C’ defaults to ‘int’ [-Wimplicit-int]
^
t.c:85:1: note: in expansion of macro ‘nh5_cleanup_c’
nh5_cleanup_c(_fcd base_name, size_t_f base_namelen, hid_t_f fapl)
^
t.c:95:23: error: ‘fapl’ undeclared (first use in this function)
c_fapl = (hid_t)*fapl;
^
t.c:100:44: error: ‘base_name’ undeclared (first use in this function)
c_base_name[0] = (char *)HD5f2cstring(base_name, (size_t)*base_namelen);
^
t.c:100:64: error: ‘base_namelen’ undeclared (first use in this function)
c_base_name[0] = (char *)HD5f2cstring(base_name, (size_t)*base_namelen);
^
In file included from t.c:26:0:
t.h:25:39: warning: unused parameter ‘h5_cleanup_c’ [-Wunused-parameter]
^
t.c:85:1: note: in expansion of macro ‘nh5_cleanup_c’
nh5_cleanup_c(_fcd base_name, size_t_f base_namelen, hid_t_f fapl)
^
t.c: At top level:
t.h:26:39: error: ‘H5_FC_FUNC_’ declared as function returning a function
^
t.c:134:1: note: in expansion of macro ‘nh5_exit_c’
nh5_exit_c(int_f *status)
^
t.h:26:39: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
^
t.c:134:1: note: in expansion of macro ‘nh5_exit_c’
nh5_exit_c(int_f *status)
^
t.h:24:39: note: previous definition of ‘H5_FC_FUNC_’ was here
^
t.c:134:1: note: in expansion of macro ‘nh5_exit_c’
nh5_exit_c(int_f *status)
^
t.h:26:39: warning: type of ‘h5_exit_c’ defaults to ‘int’ [-Wimplicit-int]
^
t.c:134:1: note: in expansion of macro ‘nh5_exit_c’
nh5_exit_c(int_f *status)
^
t.h:26:39: warning: type of ‘H5_EXIT_C’ defaults to ‘int’ [-Wimplicit-int]
^
t.c:134:1: note: in expansion of macro ‘nh5_exit_c’
nh5_exit_c(int_f *status)
^
In file included from t.h:15:0,
from t.c:26:
t.c:136:18: error: ‘status’ undeclared (first use in this function)
HDexit((int)*status);
^
../../src/H5private.h:758:31: note: in definition of macro ‘HDexit’ define HDexit(N) exit(N)
^
In file included from t.c:26:0:
t.h:26:39: warning: unused parameter ‘h5_exit_c’ [-Wunused-parameter]
^
t.c:134:1: note: in expansion of macro ‘nh5_exit_c’
nh5_exit_c(int_f *status)
^
t.c: At top level:
t.h:27:39: error: ‘H5_FC_FUNC_’ declared as function returning a function
^
t.c:151:1: note: in expansion of macro ‘nh5_env_nocleanup_c’
nh5_env_nocleanup_c(int_f *status)
^
t.h:27:39: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
^
t.c:151:1: note: in expansion of macro ‘nh5_env_nocleanup_c’
nh5_env_nocleanup_c(int_f *status)
^
t.h:24:39: note: previous definition of ‘H5_FC_FUNC_’ was here
^
t.c:151:1: note: in expansion of macro ‘nh5_env_nocleanup_c’
nh5_env_nocleanup_c(int_f *status)
^
t.h:27:39: warning: type of ‘h5_env_nocleanup_c’ defaults to ‘int’ [-Wimplicit-int]
^
t.c:151:1: note: in expansion of macro ‘nh5_env_nocleanup_c’
nh5_env_nocleanup_c(int_f *status)
^
t.h:27:39: warning: type of ‘H5_ENV_NOCLEANUP_C’ defaults to ‘int’ [-Wimplicit-int]
^
t.c:151:1: note: in expansion of macro ‘nh5_env_nocleanup_c’
nh5_env_nocleanup_c(int_f *status)
^
t.c:153:4: error: ‘status’ undeclared (first use in this function)
*status = (int_f)0;
^
In file included from t.c:26:0:
t.h:27:39: warning: unused parameter ‘h5_env_nocleanup_c’ [-Wunused-parameter]
^
t.c:151:1: note: in expansion of macro ‘nh5_env_nocleanup_c’
nh5_env_nocleanup_c(int_f status)
^
t.c: In function ‘H5_FC_FUNC_’:
t.c:70:13: warning: ‘noreturn’ function does return
return ret_value;
^
t.c: In function ‘H5_FC_FUNC_’:
t.c:137:1: warning: control reaches end of non-void function [-Wreturn-type]
} / h5_exit_c /
^
t.c: In function ‘H5_FC_FUNC_’:
t.c:156:1: warning: control reaches end of non-void function [-Wreturn-type]
} / h5_env_nocleanup_c */
^
Makefile:967: recipe for target ‘t.lo’ failed
make[2]: *** [t.lo] Error 1
make[2]: Leaving directory ‘/usr/local/src/hdf5-1.10.2/fortran/test’
Makefile:812: recipe for target ‘all-recursive’ failed
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory ‘/usr/local/src/hdf5-1.10.2/fortran’
Makefile:652: recipe for target ‘all-recursive’ failed
make: *** [all-recursive] Error 1
This was an interesting one! I was able replicate error on a Ubuntu 16.04 system and found if I explicitly set the FCLIBS environment variable to use the libraries listed below, or use “pgcc” instead of “gcc”, then HDF5 builds correctly.
Be sure to change the library directory to your PGI directory:
Basically this looks be a change in the GNU linker between the the 4.x and 5.x releases. In configure, it first tries to figure out the Fortran libraries that it needs by listing the verbose (-v) output from a simple compile. Here’s example of the link line we produce:
Because of a circular dependency, we list the Fortran runtime library (libpg90rtl.a) twice. Once at the beginning of the line, and once after libpgf902.
However configure removes the second “-lpgf90rtl” when creating FCLIBS:
This behavior is not new and how previous version of HDF5’s configure worked. Also, these are the same libraries PGI has used in the past.
What I believe is new, is how the gcc linker is working. Previous versions, such as gcc 4.8.5 which is what I was using for my original test, the linker was able to resolve the symbols libpgf902 uses from libpgf90rtl even though the library comes before it. With gcc 5.4, the linker is unable to resolve these symbols.
This then causes a cascade of errors.
First the test to check Fortran name mangling to fails
This then causes the HDF5 config header file to not define the name mangling macro
Since the macro is not defined, the compilation of the C file fails since the function that should have been preprocessed isn’t and the prototype looks like it’s returning function.
So the two solutions are to not let configure figure out the Fortran compiler’s libraries (i.e. set FCLIBS) or use pgcc instead of gcc. pgcc uses “ld” as the linker and seems to be able to resolve these symbols.