tst03_f77_v2.F:(.data+0x84): undefined reference to `tests_'

Hello,

I am trying to build netcdf-fortran 4.4.2 using PGI compilers. I am using the following configure command:

./configure --prefix=/usr/local/netcdf/fortran \
CC=pgcc \
FC=pgfortran \
F77=pgfortran \
CPPFLAGS=-I/usr/local/netcdf/c/include \
LDFLAGS=-L/usr/local/netcdf/c/lib

After doing

make check

, the following was prompted:

Making check in nf03_test
make[1]: Entering directory '/tmp/netcdf-fortran-4.4.2/nf03_test'
make  nf03_test f03tst_vars f03tst_vars2 f03tst_vars3 f03tst_vars4 f03tst_vars5 f03tst_vars6 f03tst_types f03tst_types2 f03tst_types3 f03tst_groups f03tst_v2  f03test tst03_f77_v2
make[2]: Entering directory '/tmp/netcdf-fortran-4.4.2/nf03_test'
make[2]: 'nf03_test' is up to date.
make[2]: 'f03tst_vars' is up to date.
make[2]: 'f03tst_vars2' is up to date.
make[2]: 'f03tst_vars3' is up to date.
make[2]: 'f03tst_vars4' is up to date.
make[2]: 'f03tst_vars5' is up to date.
make[2]: 'f03tst_vars6' is up to date.
make[2]: 'f03tst_types' is up to date.
make[2]: 'f03tst_types2' is up to date.
make[2]: 'f03tst_types3' is up to date.
make[2]: 'f03tst_groups' is up to date.
make[2]: 'f03tst_v2' is up to date.
make[2]: 'f03test' is up to date.
/bin/sh ../libtool  --tag=F77   --mode=link pgfortran -I../fortran   -I../fortran -I../nf_test -DpgiFortran=1  -L/usr/local/netcdf/c/lib -o tst03_f77_v2 tst03_f77_v2.o ../fortran/libnetcdff.la -lnetcdf 
libtool: link: pgfortran -I../fortran -I../fortran -I../nf_test -DpgiFortran=1 -o .libs/tst03_f77_v2 tst03_f77_v2.o  -L/usr/local/netcdf/c/lib ../fortran/.libs/libnetcdff.so -L/usr/local/hdf5/lib /usr/local/netcdf/c/lib/libnetcdf.so /usr/local/hdf5/lib/libhdf5_hl.so /usr/local/hdf5/lib/libhdf5.so -ldl -lm -lz -lcurl -Wl,-rpath -Wl,/usr/local/netcdf/fortran/lib -Wl,-rpath -Wl,/usr/local/netcdf/c/lib -Wl,-rpath -Wl,/usr/local/hdf5/lib
tst03_f77_v2.o: In function `.C1_283':
tst03_f77_v2.F:(.data+0x84): undefined reference to `tests_'
Makefile:908: recipe for target 'tst03_f77_v2' failed
make[2]: *** [tst03_f77_v2] Error 2
make[2]: Leaving directory '/tmp/netcdf-fortran-4.4.2/nf03_test'
Makefile:1322: recipe for target 'check-am' failed
make[1]: *** [check-am] Error 2
make[1]: Leaving directory '/tmp/netcdf-fortran-4.4.2/nf03_test'
Makefile:544: recipe for target 'check-recursive' failed
make: *** [check-recursive] Error 1

Any ideas about how to solve this issue?

Best Regards,

Néstor Waldyd

PD: The code builds flawlessly using gfortran:

./configure --prefix=/usr/local/netcdf/fortran \
CC=gcc \
FC=gfortran \
F77=gfortran \
CPPFLAGS=-I/usr/local/netcdf/c/include \
LDFLAGS=-L/usr/local/netcdf/c/lib

I think the fortran switches you need to add to the configuration are
Mpreprocess to preprocess fortran, and Mbackslash to treat the backslash
character as not an escape character.

FC=pgfortran -Mpreprocess -Mbackslash

will make sure all fortran programs are preprocessed, and that the
preprocessor properly handles the ‘’ character.

I’m not 100% convinced that this is a PGI compiler issue, as opposed to an issue with the NetCDF-Fortran makefiles. The unresolved symbol is happening because the Makefile is not adding the module_tests.o object file on the link line.

If you edit the nf03_tests/Makefile, you can add this file at around line 291:

am_tst03_f77_v2_OBJECTS =  module_tests.$(OBJEXT) \
        tst03_f77_v2.$(OBJEXT)

(add module_tests.$(OBJEXT) as shown here)

With this change, I can get the entire NetCDF-Fortran test suite to pass with PGI.

Hope this helps.

Best regards,

+chris