@@ -191,9 +191,8 @@ set_target_properties(core_objects PROPERTIES
191191)
192192
193193target_include_directories (core_objects PUBLIC ${PYBIND11_INCLUDE_DIRS} )
194- # BUILDING_NODE_LIBRARY must not leak to static library consumers on Windows,
195- # otherwise headers mark Node symbols as dllimport/dllexport and MSVC links
196- # against import stubs that do not exist for static linkage.
194+ # core_objects contributes to both static and shared variants; compile with
195+ # export annotations enabled where definitions are emitted.
197196target_compile_definitions (core_objects PRIVATE BUILDING_NODE_LIBRARY )
198197# Keep pybind11 usage requirements attached to the object target so core
199198# sources that include <pybind11/...> (e.g. numpy.h) always compile.
@@ -215,13 +214,6 @@ target_link_libraries(core_static PUBLIC
215214 ${NUMPY_LIBRARIES}
216215)
217216
218- if (MSVC )
219- # Core modules currently link against core_static on Windows.
220- # Force neutral visibility macro for those consumers to avoid
221- # __declspec(dllimport) decoration when no DLL import lib is used.
222- target_compile_definitions (core_static PUBLIC NODE_EXPORT= )
223- endif ()
224-
225217add_library (core_shared SHARED $<TARGET_OBJECTS :core_objects >)
226218set_target_properties (core_shared PROPERTIES
227219 CXX_VISIBILITY_PRESET default
@@ -239,6 +231,17 @@ target_link_libraries(core_shared PUBLIC
239231 ${NUMPY_LIBRARIES}
240232)
241233
234+ # Linking strategy by platform:
235+ # - MSVC: link extension modules against core_shared to avoid static-link
236+ # import/export decoration mismatches.
237+ # - Other platforms: keep static linkage to preserve previous Linux/macOS
238+ # behavior that avoids unresolved symbols from split modules.
239+ if (MSVC )
240+ set (CORE_LINK_TARGET core_shared)
241+ else ()
242+ set (CORE_LINK_TARGET core_static)
243+ endif ()
244+
242245if (APPLE )
243246 set_target_properties (core_shared PROPERTIES
244247 INSTALL_RPATH "@loader_path"
@@ -304,15 +307,15 @@ if(ENABLE_MPI)
304307endif ()
305308
306309pybind11_add_module (core MODULE src/c++/core_pybind.cpp )
307- target_link_libraries (core PRIVATE core_static )
308- add_dependencies (core core_static )
310+ target_link_libraries (core PRIVATE ${CORE_LINK_TARGET} )
311+ add_dependencies (core ${CORE_LINK_TARGET} )
309312if (APPLE )
310313 target_link_options (core PRIVATE "-Wl,-rpath,@loader_path" )
311314endif ()
312315
313316pybind11_add_module (_cgns MODULE src/c++/cgns_pybind.cpp )
314- target_link_libraries (_cgns PRIVATE core_static )
315- add_dependencies (_cgns core_static )
317+ target_link_libraries (_cgns PRIVATE ${CORE_LINK_TARGET} )
318+ add_dependencies (_cgns ${CORE_LINK_TARGET} )
316319if (APPLE )
317320target_link_options (_cgns PRIVATE "-Wl,-rpath,@loader_path" )
318321endif ()
@@ -332,9 +335,9 @@ install(DIRECTORY include DESTINATION ${SKBUILD_PROJECT_NAME})
332335# if(ENABLE_TESTS)
333336# file(GLOB_RECURSE TEST_FILES "tests/*.cpp" "tests/*.hpp")
334337# pybind11_add_module(tests MODULE ${TEST_FILES})
335- # target_link_libraries(tests PRIVATE core_static )
338+ # target_link_libraries(tests PRIVATE ${CORE_LINK_TARGET} )
336339# target_include_directories(tests PRIVATE ${CMAKE_INSTALL_INCLUDEDIR} ${CMAKE_SOURCE_DIR}/tests)
337- # add_dependencies(tests core_static )
340+ # add_dependencies(tests ${CORE_LINK_TARGET} )
338341# if(APPLE)
339342# target_link_options(tests PRIVATE "-Wl,-rpath,@loader_path")
340343# endif()
@@ -356,12 +359,12 @@ if(ENABLE_TESTS)
356359 CXX_VISIBILITY_PRESET default
357360 VISIBILITY_INLINES_HIDDEN OFF
358361 )
359- target_link_libraries (tests PRIVATE core_static )
362+ target_link_libraries (tests PRIVATE ${CORE_LINK_TARGET} )
360363 target_include_directories (tests PRIVATE
361364 ${CMAKE_INSTALL_INCLUDEDIR}
362365 ${CMAKE_SOURCE_DIR} /tests
363366 )
364- add_dependencies (tests core_static )
367+ add_dependencies (tests ${CORE_LINK_TARGET} )
365368
366369 if (APPLE )
367370 target_link_options (tests PRIVATE "-Wl,-rpath,@loader_path" )
0 commit comments