Skip to content

Commit 8363c50

Browse files
committed
Fix Windows: Shared (DLL) Builds Export
GPUDataRegistry in src/elements/mixin/dynamicdata.H uses function-local statics (next_id, registry) inside template member functions. With explicit template instantiation IMPACTX_GPUDATA_INSTANTIATE), this works for static builds. However, for DLL/shared library builds, each DLL that links the library could get its own copy of these statics unless the explicit instantiations are properly exported with visibility attributes.
1 parent 19f5905 commit 8363c50

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,15 @@ set_target_properties(lib PROPERTIES
175175
WINDOWS_EXPORT_ALL_SYMBOLS ON
176176
)
177177

178+
include(GenerateExportHeader)
179+
generate_export_header(lib
180+
BASE_NAME impactx
181+
EXPORT_FILE_NAME src/impactx_export.H
182+
)
183+
if(NOT BUILD_SHARED_LIBS)
184+
target_compile_definitions(lib PUBLIC IMPACTX_STATIC_DEFINE)
185+
endif()
186+
178187
# Optional: build only a single TU
179188
if(ImpactX_UNITY_BUILD)
180189
set_target_properties(lib PROPERTIES

src/elements/mixin/dynamicdata.H

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#ifndef IMPACTX_ELEMENTS_MIXIN_DYNAMICDATA_H
1111
#define IMPACTX_ELEMENTS_MIXIN_DYNAMICDATA_H
1212

13+
#include "impactx_export.H"
14+
1315
#include <AMReX_Gpu.H>
1416

1517
#include <map>
@@ -137,7 +139,7 @@ namespace impactx::elements::mixin
137139
* @param ElementType The element class (must define `using DynamicData = ...`)
138140
*/
139141
#define IMPACTX_GPUDATA_INSTANTIATE(ElementType) \
140-
template struct impactx::elements::mixin::GPUDataRegistry< \
142+
template struct IMPACTX_EXPORT impactx::elements::mixin::GPUDataRegistry< \
141143
ElementType::DynamicData::DataType>;
142144

143145
#endif // IMPACTX_ELEMENTS_MIXIN_DYNAMICDATA_H

0 commit comments

Comments
 (0)