Error building shared libraries

Compiling some apps with the HPC(20.9) compilers has resulted in several error messages of the type relocation R_AARCH64_ADR_PREL_PG_HI21. This happens when trying to build a shared library with autotools. An example is netcdf-fortran ( ) that results in the error:

libtool: compile:  /opt/openmpi/bin/mpif90 -I. -g -c nf_fortv2.f90 -o nf_fortv2.o >/dev/null 2>&1
/bin/bash ../libtool  --tag=FC   --mode=link /opt/openmpi/bin/mpif90 -I. -g -version-info 7:0:0 -L/opt/openmpi/lib -L/opt/hdf5/lib -L/opt/netcdf/lib -lcurl -o -rpath /opt/netcdf/lib nf_attio.lo nf_control.lo nf_dim.lo nf_misc.lo nf_genatt.lo nf_geninq.lo nf_genvar.lo nf_vario.lo nf_var1io.lo nf_varaio.lo nf_varmio.lo nf_varsio.lo nf_logging.lo nf_nc.lo  nf_v2compat.lo nf_fortv2.lo nf_lib.lo nf_nc4.lo -lnetcdf -lm
libtool: link: /opt/openmpi/bin/mpif90 -shared   .libs/nf_attio.o .libs/nf_control.o .libs/nf_dim.o .libs/nf_misc.o .libs/nf_genatt.o .libs/nf_geninq.o .libs/nf_genvar.o .libs/nf_vario.o .libs/nf_var1io.o .libs/nf_varaio.o .libs/nf_varmio.o .libs/nf_varsio.o .libs/nf_logging.o .libs/nf_nc.o .libs/nf_v2compat.o .libs/nf_fortv2.o .libs/nf_lib.o .libs/nf_nc4.o   --whole-archive ./.libs/libtypeSizes.a ./.libs/libnetcdf_nc_data.a ./.libs/libnetcdf_nf_data.a ./.libs/libnetcdf_nc_interfaces.a ./.libs/libnetcdf_nf_interfaces.a ./.libs/libnetcdfm.a ./.libs/libnetcdf_f03.a ./.libs/libnetcdf_fortv2_c_interfaces.a ./.libs/libnetcdf4_nc_interfaces.a ./.libs/libnetcdf4_nf_interfaces.a ./.libs/libnetcdf4_f03.a --no-whole-archive  -L/opt/openmpi/lib -L/opt/hdf5/lib -L/opt/netcdf/lib -lcurl /opt/hdf5/lib/ /opt/hdf5/lib/ -ldl -lz /opt/netcdf/lib/ -lm  -g   -soname -o .libs/
/usr/bin/ld: .libs/nf_dim.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol `pgf90_ptr_alloc04a_i8' which may bind externally can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: .libs/nf_dim.o(.text+0x28): unresolvable R_AARCH64_ADR_PREL_PG_HI21 relocation against symbol `pgf90_ptr_alloc04a_i8'
/usr/bin/ld: final link failed: bad value
make[2]: *** [Makefile:734:] Error 2
make[2]: Leaving directory '/home/ubuntu/netcdf-fortran/fortran'
make[1]: *** [Makefile:626: all] Error 2
make[1]: Leaving directory '/home/ubuntu/netcdf-fortran/fortran'
make: *** [Makefile:581: all-recursive] Error 1

The -fPIC flag is on (for compilers & pre-compiler) so I’m not sure why it keeps asking for it. Thanks.

It doesn’t look like the “-fPIC” option is getting added to your compile options. I’m not sure what setting your using nor know why “-fPIC” isn’t actually getting added, but I’d start by trying understand why it’s not there.


Hi Mat,
My expertise doesn’t include autotools (beyond the basics) but my understanding was that libtool includes -fPIC when necessary (and it’s usually unnecessary to have to explicitly declare it). Hence, I went back and recompiled the apps with GNU compilers; I actually did it twice, one without asking for -fPIC and the other declaring it explicitly. It didn’t matter a lot because the former added the flag. Anyway, the compilation at the same point shows
libtool: link: /opt/openmpi/bin/mpif90 -shared -fPIC .libs/nf_attio.o .libs/nf_control.o .libs/nf_dim.o .libs/nf_misc.o .libs/nf_genatt.o .libs/nf_geninq.o .libs/nf_genvar.o .libs/nf_vario.o .libs/nf_var1io.o .libs/nf_varaio.o .libs/nf_varmio.o .libs/nf_varsio.o .libs/nf_logging.o .libs/nf_nc.o .libs/nf_v2compat.o .libs/nf_fortv2.o .libs/nf_lib.o .libs/nf_nc4.o -Wl,--whole-archive ./.libs/libtypeSizes.a ./.libs/libnetcdf_nc_data.a ./.libs/libnetcdf_nf_data.a ./.libs/libnetcdf_nc_interfaces.a ./.libs/libnetcdf_nf_interfaces.a ./.libs/libnetcdfm.a ./.libs/libnetcdf_f03.a ./.libs/libnetcdf_fortv2_c_interfaces.a ./.libs/libnetcdf4_nc_interfaces.a ./.libs/libnetcdf4_nf_interfaces.a ./.libs/libnetcdf4_f03.a -Wl,--no-whole-archive -L/opt/openmpi/lib -L/opt/hdf5/lib -L/opt/netcdf/lib /opt/hdf5/lib/ /opt/hdf5/lib/ -lz /usr/lib/aarch64-linux-gnu/ /opt/netcdf/lib/ -ldl -lm -g -O2 -pthread -Wl,-soname -Wl, -o .libs/
and completes w/o further issue. From testing for the last few days, the issue comes up when simultaneously using the Nvidia-HPC compilers with autotools. It’s unclear which is causing this friction but figuring this out is definitely a priority. Thanks.

Same here, so I may not be of much help. But given the compile line above it doesn’t look like it’s actually including the -fPIC option.

Now the NVHPC package is new so libtool may not recognize the compilers so doesn’t know what to add. I’m not sure it the “-prefer-pic” option always adds “-fPIC” or if it tries to detect which compiler is being used and then add the appropriate flag.

You might try telling libtool that you’re using the PGI compilers (NVHPC is the rebranded PGI), but PGI was never released on ARM so may not work.

Or you might try setting “CFLAGS=-fPIC” in your environment to see if libtools picks it up that way. At least according to the libtool docs ( it should.

Setting CFLAGS=-fPIC is what I was trying. I’m opening a thread with the GNU Team; hopefully they’ll have some suggestion.