Repository navigation
Give run_mode and rel_max_lost_particles C linkage - #4050
Merged
paulromano merged 1 commit intoAug 5, 2026
Merged
Conversation
openmc.lib reads both of these through ctypes in_dll using their plain
names, but both were declared in namespace openmc::settings without
extern "C", so the symbols are name-mangled and the lookup has never
resolved. On a Linux build:
>>> ctypes.c_int.in_dll(dll, 'run_mode')
ValueError: openmc/lib/libopenmc.so: undefined symbol: run_mode
nm shows why: _ZN6openmc8settings8run_modeE and
_ZN6openmc8settings22rel_max_lost_particlesE. So
openmc.lib.settings.run_mode raises through its property getter, and
openmc.lib.settings.rel_max_lost_particles raises through the _DLLGlobal
descriptor. Every other global in this file that openmc.lib reads is
already declared extern "C", including max_lost_particles on the line
immediately above rel_max_lost_particles.
This is not platform specific. The two symbols are mangled on Linux,
macOS and Windows alike.
rel_max_lost_particles has been broken since it was introduced.
d763806 renamed it from relative_max_lost_particles on both the C++
and Python sides to make the names match, but with no extern "C" the
symbol never matched under either spelling.
After the change, both resolve and read the correct values, with
rel_max_lost_particles giving the 1.0e-6 default from settings.cpp:
run_mode = 0 (RunMode::UNSET)
rel_max_lost_particles = 1e-06
solver_type is left alone since openmc.lib does not read it.
paulromano
approved these changes
Aug 5, 2026
paulromano
enabled auto-merge (squash)
August 5, 2026 14:42
GuySten
suggested changes
Aug 5, 2026
GuySten
left a comment
Contributor
There was a problem hiding this comment.
RunMode is not a C type.
According to Gemini we should declare it to inherit from some int type.
Contributor
|
@GuySten when it is not declared to inherit from a type specifically, the standard says it is an |
Contributor
|
My bad. |
GuySten
approved these changes
Aug 5, 2026
jon-proximafusion
added a commit
to shimwell/openmc
that referenced
this pull request
Aug 11, 2026
The only conflict was in include/openmc/settings.h, where develop gained the same C linkage for run_mode and rel_max_lost_particles from openmc-dev#4050 that this branch added for the Windows DLL exports. Resolved by keeping develop's linkage together with this branch's OPENMC_API annotations and the openmc/export.h include, which develop does not have.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
openmc.libreads both of these globals and both are declared innamespace openmc::settingswithoutextern "C", so the symbols are name-mangled and the lookup has never resolved.On a Linux build of current
develop:Checklist
- [ ] I have followed the style guidelines for Python source files (if applicable)- [ ] I have made corresponding changes to the documentation (if applicable)