Link error: undefined reference to 'pgf'

HI, I am trying to immigrate my CFD code to GPU using NVC++, However, i got some errors showing as follow,

/usr/local/bin/ld: /opt/nvidia/hpc_sdk/Linux_x86_64/23.3/compilers/lib/liblapack.so: undefined reference to `pgf90_str_cpy1'
/usr/local/bin/ld: /opt/nvidia/hpc_sdk/Linux_x86_64/23.3/compilers/lib/liblapack.so: undefined reference to `pgf90_strcmp_klen'
/usr/local/bin/ld: /opt/nvidia/hpc_sdk/Linux_x86_64/23.3/compilers/lib/liblapack.so: undefined reference to `pgf90_str_copy_klen'
/usr/local/bin/ld: /opt/nvidia/hpc_sdk/Linux_x86_64/23.3/compilers/lib/liblapack.so: undefined reference to `pghpf_maxloc_i8'
/usr/local/bin/ld: /opt/nvidia/hpc_sdk/Linux_x86_64/23.3/compilers/lib/liblapack.so: undefined reference to `pgf90_set_intrin_type_i8'
/usr/local/bin/ld: /opt/nvidia/hpc_sdk/Linux_x86_64/23.3/compilers/lib/liblapack.so: undefined reference to `__get_size_of'
pgacclnk: child process exit status 1: /usr/local/bin/ld

My NVIDIA HPC SDK version is 23.3. Actually, i really can not find libpgf90*.so, only I can find is the compiler.

$ find /opt/ -name *pgf*
/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/compilers/bin/pgfortran
/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/compilers/bin/pgf77
/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/compilers/bin/pgf95
/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/compilers/bin/pgf90
/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/compilers/man/cat1/pgf77.1
/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/compilers/man/cat1/pgf90.1
/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/compilers/man/cat1/pgfortran.1
/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/compilers/man/cat1/pgf95.1
/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/compilers/man/man1/pgf77.1
/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/compilers/man/man1/pgf90.1
/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/compilers/man/man1/pgfortran.1
/opt/nvidia/hpc_sdk/Linux_x86_64/23.3/compilers/man/man1/pgf95.1

How can i fix the problem?

Add the flag “-fortranlibs” to your link line so the Fortran runtime libraries are added. Lapack is built with nvfortran, hence needs these libraries.

Actually, i really can not find libpgf90*.so, only I can find is the compiler.

The libraries were renamed to use the “nv” prefix when we rebranded PGI to NVHPC SDK, though we didn’t rename the internal symbols.

Hope this helps,
Mat

It works, thanks a lot.

I was getting the following error

/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java: symbol lookup error: /opt/nvidia/hpc_sdk/Linux_x86_64/23.9/compilers/lib/liblapack.so: undefined symbol: pgf90_str_copy_klen
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java: symbol lookup error: /opt/nvidia/hpc_sdk/Linux_x86_64/23.9/compilers/lib/liblapack.so: undefined symbol: pgf90_str_copy_klen

Using the following command and your discussion above, I found out that libnvf.so has the required symbol.

nm -D /opt/nvidia/hpc_sdk/Linux_x86_64/23.9/compilers/lib/libnvf.so | grep pgf90_str_copy_klen

So I decided to see if liblapack.so has dependency on that library. It seems it doesn’t

patchelf --print-needed liblapack.so

libblas_lp64.so.0
libacchost.so
libdl.so.2
libnvomp.so
libatomic.so.1
libpthread.so.0
libnvcpumath.so
libnvc.so
libc.so.6
libgcc_s.so.1
libm.so.6

ldd liblapack.so

||linux-vdso.so.1 (0x00007ffc1fbef000)|
|---|---|
||libblas_lp64.so.0 => /opt/nvidia/hpc_sdk/Linux_x86_64/23.9/compilers/lib/./libblas_lp64.so.0 (0x00007f86c3778000)|
||libacchost.so => /opt/nvidia/hpc_sdk/Linux_x86_64/23.9/compilers/lib/./libacchost.so (0x00007f86c3400000)|
||libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f86c6a5a000)|
||libnvomp.so => /opt/nvidia/hpc_sdk/Linux_x86_64/23.9/compilers/lib/./libnvomp.so (0x00007f86c2200000)|
||libatomic.so.1 => /lib/x86_64-linux-gnu/libatomic.so.1 (0x00007f86c6a4e000)|
||libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f86c6a49000)|
||libnvcpumath.so => /opt/nvidia/hpc_sdk/Linux_x86_64/23.9/compilers/lib/./libnvcpumath.so (0x00007f86c1c00000)|
||libnvc.so => /opt/nvidia/hpc_sdk/Linux_x86_64/23.9/compilers/lib/./libnvc.so (0x00007f86c1800000)|
||libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f86c1400000)|
||libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f86c6a27000)|
||libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f86c6940000)|
||/lib64/ld-linux-x86-64.so.2 (0x00007f86c6a81000)|

So I decided to add the dependency to liblapack.so using patchelf

patchelf --add-needed libnvf.so /opt/nvidia/hpc_sdk/Linux_x86_64/23.9/compilers/lib/./libnvf.so liblapack.so

Now the library has dependency on libnvf.so properly.

||linux-vdso.so.1 (0x00007ffc1fbef000)|
|---|---|
||libnvf.so => /opt/nvidia/hpc_sdk/Linux_x86_64/23.9/compilers/lib/./libnvf.so (0x00007f86c5600000)|
||libblas_lp64.so.0 => /opt/nvidia/hpc_sdk/Linux_x86_64/23.9/compilers/lib/./libblas_lp64.so.0 (0x00007f86c3778000)|
||libacchost.so => /opt/nvidia/hpc_sdk/Linux_x86_64/23.9/compilers/lib/./libacchost.so (0x00007f86c3400000)|
||libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f86c6a5a000)|
||libnvomp.so => /opt/nvidia/hpc_sdk/Linux_x86_64/23.9/compilers/lib/./libnvomp.so (0x00007f86c2200000)|
||libatomic.so.1 => /lib/x86_64-linux-gnu/libatomic.so.1 (0x00007f86c6a4e000)|
||libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f86c6a49000)|
||libnvcpumath.so => /opt/nvidia/hpc_sdk/Linux_x86_64/23.9/compilers/lib/./libnvcpumath.so (0x00007f86c1c00000)|
||libnvc.so => /opt/nvidia/hpc_sdk/Linux_x86_64/23.9/compilers/lib/./libnvc.so (0x00007f86c1800000)|
||libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f86c1400000)|
||libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f86c6a27000)|
||libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f86c6940000)|
||/lib64/ld-linux-x86-64.so.2 (0x00007f86c6a81000)|

Hi dineshdharme,

Yes, this is a know artifact on how we build the OpenBLAS lapack and BLAS libraries. It typically doesn’t matter since most folks use these libraries with our compilers, but is a problem when linking with other tools.

We’ve opened a problem report, TPR #34647, and see if we can get it corrected.

Thanks,
Mat