Skip to content

Undefined symbol : pfnc_inq_vardimid during import netCDF4 #1417

Open

Description

@fparadiss

Dear devs,

Here's the information about my build :

  • Python: 3.11.5
  • netCDF4-python: 1.7.2 (same result with pip install and from source via pip install .)
  • netcdf-c: 4.9.3 (custom build, with nc_complex enabled)
  • HDF5: 1.14.6
  • OS: Rocky Linux 8.10

Trying to install netcdf4-python from : pip install netCDF4 or from source code : pip install . I get the following error when trying to import netCDF4 in python although there is no error during the installation :

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/fparadis/pyenv/lib/python3.11/site-packages/netCDF4/__init__.py", line 3, in <module>
    from ._netCDF4 import *
ImportError: /home/fparadis/pyenv/lib/python3.11/site-packages/netCDF4/_netCDF4.cpython-311-x86_64-linux-gnu.so: undefined symbol: pfnc_inq_vardimid

From my current understanding, these symbols are defined inside nc_complex which should be automatically added during the installation of netCDF4-python. However, I've also tried to install manually nc_complex and link them using LD_LIBRARY_PATH but to no success. Using nm -D, I can see the symbols pfnc_inq_vardimid is correctly defined in libnc_complex.so.

As I don't need nc_complex in my installation, I was wondering if it is either possible to deactivate nc_complex or how to correctly link the symbols to it.

Thanks in advance, Félix

Activity

  1. jswhit commented on Aug 5, 2025

    @jswhit
    Collaborator
  2. jswhit commented on Aug 5, 2025

    @jswhit
    Collaborator

    When you say 'netcdf-c: 4.9.3 (custom build, with nc_complex enabled)' do you mean that it's a modified version of the C-lib with nc_complex included? If so, I suspect that there is a conflict between the two versions of nc_complex (the one in the C lib and the one included in the python module).

  3. ZedThree commented on Aug 6, 2025

    @ZedThree
    Contributor

    I thought that we build nc_complex as part of the Cython build?

    netcdf4-python/setup.py

    Lines 428 to 437 in 57b9a80

    nc_complex_dir = pathlib.Path("./external/nc_complex")
    source_files = [
    netcdf4_src_pyx,
    str(nc_complex_dir / "src/nc_complex.c"),
    ]
    include_dirs = inc_dirs + [
    "include",
    str(nc_complex_dir / "include"),
    str(nc_complex_dir / "include/generated_fallbacks"),
    ]

    So I don't think you need to have built it separately.

  4. ocefpaf commented on Aug 6, 2025

    @ocefpaf
    Collaborator

    Also, I cannot reproduce that with the built wheel. Your pip install is probably from source, right? If so, something is amiss with your build.

  5. Cor0n4V1rus commented on Sep 15, 2026

    @Cor0n4V1rus

    I had the same issue, with at least 1.7.2 and 1.7.4 and fixed it with two 'dirty' patches.
    Since I am no expert with python, cython, numpy, hdf5 or netcdf, someone with
    deeper knowledge might want to fix it properly.

    First one removes 'inline' from the two functions AND makes them invisible, if a
    compile unit defines 'NO_INLINE_FUNCTIONS', otherwise the linker would complain about
    multiple symbol definitions.

    Second patch defines 'NO_INLINE_FUNCTIONS' before including the header.

    --- external/nc_complex/include/nc_complex/nc_complex.h.original
    +++ external/nc_complex/include/nc_complex/nc_complex.h
    @@ -242,14 +242,16 @@
         int* nattsp
     );
     
    +#ifndef NO_INLINE_FUNCTIONS
     // NOLINTBEGIN(modernize-use-nullptr)
    -NC_COMPLEX_EXPORT inline int pfnc_inq_varndims(int ncid, int varid, int* ndimsp) {
    +NC_COMPLEX_EXPORT int pfnc_inq_varndims(int ncid, int varid, int* ndimsp) {
         return pfnc_inq_var(ncid, varid, NULL, NULL, ndimsp, NULL, NULL);
     }
    -NC_COMPLEX_EXPORT inline int pfnc_inq_vardimid(int ncid, int varid, int* dimidsp) {
    +NC_COMPLEX_EXPORT int pfnc_inq_vardimid(int ncid, int varid, int* dimidsp) {
         return pfnc_inq_var(ncid, varid, NULL, NULL, NULL, dimidsp, NULL);
     }
     // NOLINTEND(modernize-use-nullptr)
    +#endif
     
     NC_COMPLEX_EXPORT int pfnc_def_var_chunking(
         int ncid, int varid, int storage, const size_t* chunksizesp
    
    --- external/nc_complex/src/nc_complex.c.original
    +++ external/nc_complex/src/nc_complex.c
    @@ -1,3 +1,4 @@
    +#define NO_INLINE_FUNCTIONS
     #include "nc_complex/nc_complex.h"
     
     #include <ctype.h>
    

    For the record (with gcc 16.2.0) :

    Without my patches, building it with

    (
    export CFLAGS+=" -Wno-incompatible-pointer-types"
    export USE_NCCONFIG=1
    export NETCDF_PLUGIN_DIR=/usr/lib/netcdf/plugin
    
    python -m build -v --wheel --no-isolation
    )
    

    and testing it with

    (
    export NO_NET=1
    export PYTHONPATH="${PWD}"/build/lib.linux-x86_64-cpython-314
    
    pushd test
    python -B ./run_all.py
    popd
    )
    

    yields

    Traceback (most recent call last):
      File "/tmp/build-bot/netcdf-1.7.4/test/./run_all.py", line 2, in <module>
        from netCDF4 import __hdf5libversion__,__netcdf4libversion__,__version__, Dataset
      File "/tmp/build-bot/netcdf-1.7.4/build/lib.linux-x86_64-cpython-314/netCDF4/__init__.py", line 11, in <module>
        from ._netCDF4 import *
    ImportError: /tmp/build-bot/netcdf-1.7.4/build/lib.linux-x86_64-cpython-314/netCDF4/_netCDF4.cpython-314-x86_64-linux-gnu.so: undefined symbol: pfnc_inq_vardimid
    

    while with the patches its

    netcdf4-python version: 1.7.4
    HDF5 lib version:       2.2.0
    netcdf lib version:     4.10.1
    numpy version           2.5.3
    cython version          3.3.0
    s...................................................................s...........................s..........compressed lossy with shuffle and standard quantization =  187676  max err =  0.00024412745124813284
    compressed lossy with shuffle and alternate quantization =  155270  max err =  0.00048827517723559755
    compressed lossy with shuffle and alternate quantization =  162934  max err =  0.0002441371616678234
    ......s.
    ----------------------------------------------------------------------
    Ran 115 tests in 113.330s
    
    OK (skipped=4)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions