Repository navigation
[All] Windows: Fix compilation with clang for MSVC - #6402
Merged
Merged
Conversation
bakpaul
approved these changes
Oct 16, 2026
…mespace DEFAULTCOLORS has internal linkage, so exporting it is meaningless. MSVC ignores the attribute but clang-cl emits an export for it, which leaves lld-link with an undefined symbol when linking Sofa.Simulation.Core
…ngle library Sofa.Component.LinearSystem explicitly instantiates the dllexport'ed CompositeLinearSystem<BTDMatrix<6>, BlockVector<6>>, which implicitly exports its base TypedMatrixLinearSystem<BTDMatrix<6>, BlockVector<6>>. Sofa.Component.LinearSolver.Direct also instantiated and exported that same base, resulting in duplicate symbols with lld-link (clang-cl). The instantiation now lives in Sofa.Component.LinearSystem (extern template declared in TypedMatrixLinearSystem.h), and Sofa.Component.LinearSolver.Direct only registers the component.
…ssions with clang-cl FiniteElement<Hexahedron, Vec3Types> is an extern template with SOFA_FEM_API, so in other modules its static constexpr member referenceElementNodes is dllimport. clang-cl refuses to read a dllimport variable in a constant expression, breaking the constexpr evaluation of gradientShapeFunctionAtQuadraturePoints() in VonMisesStress. The reference nodes are moved to a namespace-scope variable template, which gradientShapeFunctions uses and referenceElementNodes is initialized from.
…use NodeSPtr ComponentMouseInteraction and SceneCheckerListener are dllexport'ed and copy/destroy a NodeSPtr in inline (or implicit) members. clang-cl instantiates those members eagerly, and with only a forward declaration of Node, ADL cannot find intrusive_ptr_add_ref/intrusive_ptr_release.
ParallelBruteForceBroadPhase and ParallelBVHNarrowPhase are dllexport'ed and hold std::vector of a task type that is only forward-declared at that point. clang-cl instantiates the inline/implicit destructor of an exported class immediately, which requires the complete element type. The destructors are now declared in the headers and defaulted in the .cpp files.
…seMatrixStorageOrder The four explicit specializations of buildOppositeOrder() for the Eigen sparse matrices were defined in the .cpp but never declared in the header, unlike value()/row()/col(). MSVC exported them anyway as part of the dllexported class instantiation, but clang-cl did not, so Sofa.LinearAlgebra_test failed to link. Declare them with SOFA_LINEARALGEBRA_API next to the other ones.
The experimental clang-cl branch unconditionally added -march=native to the Release options of Sofa.Config, which propagates to every target. Builds were therefore tied to the build machine's CPU (e.g. AVX-512) and not comparable with MSVC builds, which only use SIMD flags when SOFA_ENABLE_SIMD is ON. -march=native is now added in the SOFA_ENABLE_SIMD block, in place of the MSVC /arch:AVX(2) detection when the compiler is clang-cl, so it also follows the deprecated SOFA_VECTORIZE option.
fredroy
force-pushed
the
fix_msvc_cl_fixes
branch
from
October 29, 2026 13:58
10cee21 to
47d9a8e
Compare
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.
clang for msvc is much stricter than msvc itself for exported symbol and linking
By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).
Reviewers will merge this pull-request only if