# undefined symbol error due to netcdf linking

**URL:** https://discourse.vtk.org/t/undefined-symbol-error-due-to-netcdf-linking/2870
**Category:** Support
**Created:** [March 24, 2020, 7:17am UTC](https://discourse.vtk.org/t/undefined-symbol-error-due-to-netcdf-linking/2870 "2020-03-24T07:17:11Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![hubutui](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hubutui/32/1481_2.png) [@hubutui](https://discourse.vtk.org/u/hubutui)
#### Post date: [March 24, 2020, 7:17am UTC](https://discourse.vtk.org/t/undefined-symbol-error-due-to-netcdf-linking/2870/1 "2020-03-24T07:17:11Z")

</div>

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

```auto
  cmake .. \
    -DBUILD_SHARED_LIBS=ON \
    -DBUILD_TESTING=OFF \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_LIBDIR=lib \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_SKIP_INSTALL_RPATH=ON \
    -DVTK_BUILD_ALL_MODULES=ON \
    -DVTK_BUILD_TESTING=OFF \
    -DVTK_LEGACY_REMOVE=ON \
    -DVTK_MODULE_ENABLE_VTK_FiltersOpenTURNS=NO \
    -DVTK_MODULE_ENABLE_VTK_IOADIOS2=NO \
    -DVTK_MODULE_ENABLE_VTK_IOLAS=NO \
    -DVTK_MODULE_ENABLE_VTK_RenderingOpenVR=NO \
    -DVTK_MODULE_USE_EXTERNAL_VTK_gl2ps=OFF \
    -DVTK_MODULE_USE_EXTERNAL_VTK_libharu=OFF \
    -DVTK_PYTHON_VERSION="3" \
    -DVTK_QT_VERSION="5" \
    -DVTK_USE_EXTERNAL=ON \
    -DVTK_USE_FFMPEG_ENCODER=ON \
    -DVTK_USE_LARGE_DATA=ON \
    -DVTK_WRAP_PYTHON=ON

```

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

```auto
>>> 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:

```auto
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?

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [March 24, 2020, 7:25am UTC](https://discourse.vtk.org/t/undefined-symbol-error-due-to-netcdf-linking/2870/2 "2020-03-24T07:25:34Z")

</div>

@ben.boeckel

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [March 24, 2020, 11:48am UTC](https://discourse.vtk.org/t/undefined-symbol-error-due-to-netcdf-linking/2870/3 "2020-03-24T11:48:29Z")

</div>

It looks fine on Fedora:

```auto
 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)?

---

<div class="post-metadata">

### Author: ![hubutui](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hubutui/32/1481_2.png) [@hubutui](https://discourse.vtk.org/u/hubutui)
#### Post date: [March 24, 2020, 1:43pm UTC](https://discourse.vtk.org/t/undefined-symbol-error-due-to-netcdf-linking/2870/4 "2020-03-24T13:43:12Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [March 24, 2020, 4:49pm UTC](https://discourse.vtk.org/t/undefined-symbol-error-due-to-netcdf-linking/2870/5 "2020-03-24T16:49:08Z")

</div>

`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](https://gitlab.kitware.com/vtk/vtk/-/merge_requests/6614) help?

---

<div class="post-metadata">

### Author: ![hubutui](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hubutui/32/1481_2.png) [@hubutui](https://discourse.vtk.org/u/hubutui)
#### Post date: [March 24, 2020, 6:27pm UTC](https://discourse.vtk.org/t/undefined-symbol-error-due-to-netcdf-linking/2870/6 "2020-03-24T18:27:27Z")

</div>

Yes, the patch you mentioned helps.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [March 24, 2020, 6:41pm UTC](https://discourse.vtk.org/t/undefined-symbol-error-due-to-netcdf-linking/2870/7 "2020-03-24T18:41:16Z")

</div>

Thanks.
