undefined symbol error due to netcdf linking

Hi, I build vtk from the master branch for ArchLinux with configuration:

  cmake .. \
    -DCMAKE_BUILD_TYPE=Release \
    -DVTK_QT_VERSION="5" \

After install it, I try to import vtk in python, and got this error:

>>> import vtk
Traceback (most recent call last):
  File "<input>", line 1, in <module>
    import vtk
  File "/usr/lib/python3.8/site-packages/vtk.py", line 30, in <module>
    all_m = importlib.import_module('vtkmodules.all')
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/usr/lib/python3.8/site-packages/vtkmodules/all.py", line 75, in <module>
    from .vtkIOExodus import *
ImportError: /usr/lib/libvtkexodusII-9.0.so.1: undefined symbol: nc_put_var_int

This symbol is provide by netcdf, but it seems that /usr/lib/libvtkexodusII-9.0.so.1 is not properly linked with netcdf:

readelf -d /usr/lib/libvtkexodusII-9.0.so.1

Dynamic section at offset 0x655c0 contains 23 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000000e (SONAME)             Library soname: [libvtkexodusII-9.0.so.1]
 0x000000000000000c (INIT)               0x9000
 0x000000000000000d (FINI)               0x4e8fc
 0x0000000000000019 (INIT_ARRAY)         0x66570
 0x000000000000001b (INIT_ARRAYSZ)       8 (bytes)
 0x000000000000001a (FINI_ARRAY)         0x66578
 0x000000000000001c (FINI_ARRAYSZ)       8 (bytes)
 0x000000006ffffef5 (GNU_HASH)           0x260
 0x0000000000000005 (STRTAB)             0x4010
 0x0000000000000006 (SYMTAB)             0x13a0
 0x000000000000000a (STRSZ)              12475 (bytes)
 0x000000000000000b (SYMENT)             24 (bytes)
 0x0000000000000007 (RELA)               0x74d0
 0x0000000000000008 (RELASZ)             6792 (bytes)
 0x0000000000000009 (RELAENT)            24 (bytes)
 0x0000000000000018 (BIND_NOW)           
 0x000000006ffffffb (FLAGS_1)            Flags: NOW
 0x000000006ffffffe (VERNEED)            0x7480
 0x000000006fffffff (VERNEEDNUM)         1
 0x000000006ffffff0 (VERSYM)             0x70cc
 0x000000006ffffff9 (RELACOUNT)          12
 0x0000000000000000 (NULL)               0x0

If I manually add -DCMAKE_SHARED_LINKER_FLAGS="$(pkg-config --libs netcdf)" with cmake, this error dispeared. Maybe there is something missing when linking with netcdf?


It looks fine on Fedora:

 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libnetcdf.so.15]
 0x000000000000000e (SONAME)             Library soname: [libvtkexodusII-9.0.so.1]

Could you please post the linker line used for the library on your platform (without the pkg-config setting)?

I don’t know what you mean. I have post my cmake configuration when I build this package.

make VERBOSE=1 or ninja -v will output the commands used. If you get the link line for exodusII, netcdf should be there. The essence of your configuration (as far as exodusII is concerned) makes a library with the correct DT_NEEDED on my Fedora machine. If it is there on the link line, some Arch-specific linker behavior is probably dropping it as “unnecessary”. If it isn’t showing up, find_package(NetCDF) is not working properly.

Which reminds me. Does this patch help?

Yes, the patch you mentioned helps.