镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

[All] Windows: Fix compilation with clang for MSVC - #6402

Merged
epernod merged 7 commits into
sofa-framework:masterfrom
fredroy:fix_msvc_cl_fixes
Oct 29, 2026
Merged

epernod merged 7 commits into
sofa-framework:masterfrom
fredroy:fix_msvc_cl_fixes

Conversation

@fredroy

@fredroy fredroy commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

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

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).

@fredroy fredroy added pr: fix Fix a bug pr: status to review To notify reviewers to review this pull-request pr: AI-aided Label notifying the reviewers that part or all of the PR has been generated with the help of an AI labels Oct 15, 2026
@hugtalbot hugtalbot added pr: status ready Approved a pull-request, ready to be squashed and removed pr: status to review To notify reviewers to review this pull-request labels Oct 29, 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.
@epernod
epernod merged commit 7c6c19d into sofa-framework:master Oct 29, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: AI-aided Label notifying the reviewers that part or all of the PR has been generated with the help of an AI pr: fix Fix a bug pr: status ready Approved a pull-request, ready to be squashed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants