Skip to content

[BUG] pyOpenMS is unimportable when built with -DWITH_WNETALIGN=OFF (undefined symbol WNetMatcher::metricFromString) #9946

Closed

Description

@timosachsenberg

Details About Your Environment

Operating System and Hardware: Ubuntu 24.04 (noble) on x86_64, GCC 13.3.0, CMake 3.28.3, Ninja

OpenMS Version: develop (source build)

Installation Method: Other — source build via CMake


Bug Description

Building with -DWITH_WNETALIGN=OFF produces a libOpenMS.so and a full set of pyOpenMS modules with zero compile or link errors, but the resulting package cannot be imported at all:

ImportError: .../pyopenms/_pyopenms_misc.cpython-311-x86_64-linux-gnu.so: undefined symbol:
_ZN6OpenMS11WNetMatcher16metricFromStringERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE

(demangled: OpenMS::WNetMatcher::metricFromString(std::string const&))

Because pyopenms/__init__.py imports all binding modules, the failure of _pyopenms_misc makes the entire package unusable, not just the WNet functionality.

Cause

WITH_WNETALIGN removes two source files from the library, but the bindings reference them unconditionally.

  1. The sources are conditionally excluded from libOpenMS — src/openms/source/ANALYSIS/MAPMATCHING/sources.cmake:49-54:

    if(WITH_WNETALIGN)
      list(APPEND OpenMS_sources
        ${directory}/FeatureGroupingAlgorithmWNet.cpp
        ${directory}/WNetMatcher.cpp
      )
    endif()

    Note the headers are not guarded and the .cpp files contain no internal #ifdef, so with the option off the declarations still exist while the definitions do not.

  2. src/pyOpenMS/bindings/bind_misc.cpp includes and binds them unconditionally — :40, :42 and the bindings from :846 onwards:

    #include <OpenMS/ANALYSIS/MAPMATCHING/FeatureGroupingAlgorithmWNet.h>
    #include <OpenMS/ANALYSIS/MAPMATCHING/WNetMatcher.h>
    ...
    nb::enum_<OpenMS::WNetMatcher::DistanceMetric>(m, "WNetMatcherDistanceMetric", ...)

Shared modules do not resolve undefined symbols at link time, so nothing fails until import pyopenms.

Why the existing guard pattern does not currently work here

The codebase already has a working pattern for optional components, but WNet is not set up to use it:

option definition visible to pyOpenMS? guarded in bindings?
WITH_OPENTIMS target_compile_definitions(OpenMS PUBLIC WITH_OPENTIMS=1) — src/openms/CMakeLists.txt:343 yes yes — bind_format.cpp:158 #ifdef WITH_OPENTIMS
WITH_THERMO_RAW PUBLIC WITH_THERMO_RAW=1 — :347 yes n/a
WITH_WNETALIGN target_compile_definitions(OpenMS PRIVATE ... OPENMS_HAS_WNETALIGN) — :357 no (PRIVATE) no

So even if a #ifdef were added to bind_misc.cpp today, OPENMS_HAS_WNETALIGN would not be defined in that translation unit, because the definition is PRIVATE rather than PUBLIC.

Steps to Reproduce

cmake -S . -B build -G Ninja \
  -DCMAKE_BUILD_TYPE=Release -DWITH_GUI=OFF -DPYOPENMS=ON \
  -DWITH_WNETALIGN=OFF
ninja -C build pyopenms          # succeeds, 0 errors
PYTHONPATH=build/pyOpenMS python3 -c "import pyopenms"   # ImportError

Setting -DWITH_WNETALIGN=ON (the default) resolves it, so this only affects builds that deliberately turn the option off.

Suggested Fix

Follow the WITH_OPENTIMS precedent:

  1. Change src/openms/CMakeLists.txt:357 to export the macro publicly, e.g. target_compile_definitions(OpenMS PUBLIC OPENMS_HAS_WNETALIGN=1) (keeping LEMON_ONLY_TEMPLATES private, since that one is only needed when compiling the library itself).
  2. Wrap the includes and bindings in bind_misc.cpp in #ifdef OPENMS_HAS_WNETALIGN.

Alternatively, if WITH_WNETALIGN=OFF is not intended to be a supported configuration, the option could fail fast at configure time when PYOPENMS=ON, which would at least turn a late ImportError into an actionable CMake error.

Notes

  • Severity is low in practice since the option defaults to ON, but the failure mode is poor: a fully successful build that is silently unimportable, with an error that names a mangled symbol rather than the option responsible.
  • The same class of problem may exist for other optional components whose sources are conditionally excluded but whose bindings are unguarded; WITH_OPENTIMS is the only #ifdef currently present in src/pyOpenMS/bindings/*.cpp.
  • Found while doing an unrelated source build of develop; not a regression from any recent change.

Activity

  1. hello-ryuzaki commented on Aug 23, 2026

    @hello-ryuzaki

    Hi @timosachsenberg , I would like to work on this issue. Could you please assign it to me??
    Thank you

  2. timosachsenberg commented on Aug 23, 2026

    @timosachsenberg
    ContributorAuthor

    @hello-ryuzaki sure. Please go ahead. Note that building OpenMS / pyopenms is a must for contributors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions