Skip to content

Compilation error on NDK/BSDs: undefined reference to qsort_r in H5RT.c #5896

@hyoklee

Description

@hyoklee

Description

Building HDF5 fails on some systems (e.g., NDK, Net/OpenBSD) with undefined reference errors to qsort_r when linking against the R-tree implementation.

Error Message

../bin/libhdf5.a(H5RT.c.o): In function `H5RT__bulk_load':
H5RT.c:(.text+0xc48): undefined reference to `qsort_r'
H5RT.c:(.text+0x1258): undefined reference to `qsort_r'
../bin/libhdf5.a(H5RT.c.o): In function `H5RT_create':
H5RT.c:(.text+0x1af2): undefined reference to `qsort_r'
collect2: error: ld returned 1 exit status
make[2]: *** [bin/rtree] Error 1

Root Cause

The issue appears to be in src/H5RT.c which uses HDqsort_r() (line 397). The macro HDqsort_r is defined in src/H5private.h (lines 772-776) and falls back to the system's qsort_r() on non-Windows platforms when a context-based qsort is not available.

However, qsort_r is not available on older Linux systems like CentOS-5. The qsort_r function:

  • Was introduced in glibc 2.8 (2008)
  • Is not part of POSIX
  • Has different signatures across BSD and GNU systems

Expected Behavior

The code should compile successfully on CentOS-5 and other older systems by using the HDqsort_context() fallback implementation.

System Information

Suggested Fix

The HDqsort_r macro definition in src/H5private.h should detect when qsort_r is not available and fall back to HDqsort_context() on older systems. This might require a configure-time check to detect qsort_r availability.

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

Status

In progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions