Repository navigation
Description
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.
-
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
.cppfiles contain no internal#ifdef, so with the option off the declarations still exist while the definitions do not. -
src/pyOpenMS/bindings/bind_misc.cppincludes and binds them unconditionally —:40,:42and the bindings from:846onwards:#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" # ImportErrorSetting -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:
- Change
src/openms/CMakeLists.txt:357to export the macro publicly, e.g.target_compile_definitions(OpenMS PUBLIC OPENMS_HAS_WNETALIGN=1)(keepingLEMON_ONLY_TEMPLATESprivate, since that one is only needed when compiling the library itself). - Wrap the includes and bindings in
bind_misc.cppin#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_OPENTIMSis the only#ifdefcurrently present insrc/pyOpenMS/bindings/*.cpp. - Found while doing an unrelated source build of
develop; not a regression from any recent change.
Activity
hello-ryuzaki commentedon Aug 23, 2026
Hi @timosachsenberg , I would like to work on this issue. Could you please assign it to me??
Thank you
timosachsenberg commentedon Aug 23, 2026
@hello-ryuzaki sure. Please go ahead. Note that building OpenMS / pyopenms is a must for contributors.
Fix pyOpenMS import failure when built with WITH_WNETALIGN=OFF (OpenM…