View Issue Details

IDProjectCategoryView StatusLast Update
0031124Open CASCADEOCCT:Configurationpublic2020-12-02 17:12
Reporterabv Assigned Toabv  
Status closedResolutionfixed 
Product Version7.4.0 
Target Version7.5.0Fixed in Version7.5.0 
Summary0031124: Configuration - linker errors when building with CLang on Windows
DescriptionThis issue is to document strange linker errors that appear when OCCT is built with CLang on Windows (toolset Clang-CL in Visual Studio 2019). It looks to be a compiler bug.

The problem appears for classes that:

- Have virtual functions not declared as Standard_EXPORT (usually private or protected)
- Have non-trivial inline destructor (i.e. have some fields with destructors but do not have explicitly defined destrucror, or have it defined inline)
- Have out-of-line constructor (if not, the linker error is explainable)

The simplest example consists of DLL defining class CLangLinkError:


#include <Standard_Transient.hxx>

class CLangLinkError

  Standard_EXPORT CLangLinkError();

  virtual void f();

  Handle(Standard_Transient) myField; // any field with destructor


#include <CLangLinkError.hxx>

CLangLinkError::CLangLinkError() { }
void CLangLinkError::f() { }

... and another DLL or executable using that class:

#include <CLangLinkError.hxx>
CLangLinkError anObj; // causes linker error

Linker error looks as follows:

2>lld-link : error : undefined symbol: "protected: virtual void __cdecl CLangLinkError::f(void)" (?f@CLangLinkError@@UEAAXXZ)
2>>>> referenced by ....\Test.obj:("const CLangLinkError::`vftable'" (??_7CLangLinkError@@6B@))

If the object is allocated dynamically (with operator new), the problem does not reproduce, even if the object is explicitly delted by 'delete'.

If out-of-line destructor is defined for the class CLangLinkError (exported from main DLL), or the field is removed, the problem is not reproduced.

Logically there is no need for compiler to generate vtbl for that class, it should be only generated in the constructor that is defined in main DLL. Hence, the issue looks like a bug in CLang.
Steps To ReproduceBuild with CLang on Windows
TagsNo tags attached.
Test case numberNot required

Attached Files

  • (1,291 bytes)


related to 0031060 closedabv Configuration - Support building with CLang compiler under VS 2019 



2019-11-03 13:37

developer (1,291 bytes)


2019-11-03 13:39

developer   ~0088710

Last edited: 2019-11-03 13:42

I think that it is not a bug in Clang because it reproduces on MinGW64, too:

undefined reference to `vtable for Foo'

Looks like the right way to deal with such classes is to export both its constructor and destructor or inline both of them.

I've uploaded the archive containing CMake project that may help to reproduce this issue.


2019-11-03 21:52

administrator   ~0088712

Branch CR31124 has been created by abv.

SHA-1: d6e3f9fb7ec7900dd885bf372fe97ef2e1f8db73

Detailed log of new commits:

Author: abv
Date: Sat Nov 2 11:10:47 2019 +0300

    0031124: Configuration - linker errors when building with CLang on Windows
    Standard_EXPORT is added in declaration of virtual methods where it was missing, to allow creation of sub-classes in other DLLs.
    In some classes in OpenGl package Standard_EXPORT is added for all methods to make these classes usable in other DLLs.


2019-11-04 14:53

administrator   ~0088713

Branch CR31124 has been updated forcibly by abv.

SHA-1: b31fbc832ddf4fb505352f457c3596d58f002212


2019-11-04 15:24

manager   ~0088714

Timur, thank you for comment! However, if this problem is reproduced on MinGW64, why it has not been reported and addressed in 0030609?


2019-11-04 15:29

manager   ~0088715

In general case it is necessary to export all virtual methods of each non-final class, to allow generation of vtbl for derived classes if they are defined in another DLL. This is what is done in the patch, please review branch CR31124. Tests are OK indeed, see Jenkins job CR31124-abv.

This patch eliminates the original problem even if it remains quite strange and raises doubts in consistency of the code. Usually duplication of vtbl manifests in inconsistent work of RTTI, when type of the object of the affected class cannot be recognized. In the case of reported issue with CLang however everything seems to work fine according to my tests, thus we can keep it as it is.


2019-11-07 10:43

administrator   ~0088765

Tested in framework of WEEK-45

Combination -
OCCT branch : WEEK-45
master SHA - a1a9b249523438cf9b3d510fb4ff74bd4a5675b6
Products branch : WEEK-45 SHA - f88bc93e3637c4c42f3c154c0b0e167d4e297ae6
was compiled on Linux, MacOS and Windows platforms and tested in optimize mode.

Number of compiler warnings:
No new/fixed warnings

No regressions/differences

CPU differences:
Total CPU difference: 16844.70000000007 / 16848.430000000117 [-0.02%]
Total CPU difference: 10837.970000000065 / 10873.690000000062 [-0.33%]
Total CPU difference: 18366.671875 / 18319.515625 [+0.26%]
Total CPU difference: 12848.578125 / 12848.859375 [-0.00%]

Image differences :
No differences that require special attention

Memory differences :
No differences that require special attention


2019-11-10 11:41

administrator   ~0088838

Branch CR31124 has been deleted by inv.

SHA-1: b31fbc832ddf4fb505352f457c3596d58f002212

Related Changesets

occt: master b31fbc83

2019-11-02 08:10:47


Committer: abv Details Diff
0031124: Configuration - linker errors when building with CLang on Windows

Standard_EXPORT is added in declaration of virtual methods where it was missing, to allow creation of sub-classes in other DLLs.
In some classes in OpenGl package Standard_EXPORT is added for all methods to make these classes usable in other DLLs.
Affected Issues
mod - src/AIS/AIS_FixRelation.hxx Diff File
rm - src/AIS/AIS_FixRelation.lxx Diff File
mod - src/AIS/AIS_IdenticRelation.hxx Diff File
rm - src/AIS/AIS_IdenticRelation.lxx Diff File
mod - src/AIS/FILES Diff File
mod - src/BRepExtrema/BRepExtrema_SelfIntersection.hxx Diff File
mod - src/BRepMesh/BRepMesh_DefaultRangeSplitter.hxx Diff File
mod - src/Graphic3d/Graphic3d_BvhCStructureSet.hxx Diff File
mod - src/Graphic3d/Graphic3d_BvhCStructureSetTrsfPers.hxx Diff File
mod - src/Graphic3d/Graphic3d_MediaTextureSet.hxx Diff File
mod - src/OpenGl/OpenGl_GraduatedTrihedron.hxx Diff File
mod - src/OpenGl/OpenGl_LayerList.hxx Diff File
mod - src/OpenGl/OpenGl_LineAttributes.hxx Diff File
mod - src/OpenGl/OpenGl_SceneGeometry.hxx Diff File
mod - src/OpenGl/OpenGl_StencilTest.hxx Diff File
mod - src/OpenGl/OpenGl_Structure.hxx Diff File
mod - src/OpenGl/OpenGl_StructureShadow.hxx Diff File
mod - src/RWObj/RWObj_CafReader.hxx Diff File
mod - src/SelectBasics/SelectBasics_SelectingVolumeManager.hxx Diff File
mod - src/SelectMgr/SelectMgr_SelectingVolumeManager.hxx Diff File
mod - src/SelectMgr/SelectMgr_SensitiveEntitySet.hxx Diff File

Issue History

Date Modified Username Field Change
2019-11-01 23:43 abv New Issue
2019-11-01 23:43 abv Assigned To => bugmaster
2019-11-01 23:45 abv Description Updated
2019-11-01 23:46 abv Description Updated
2019-11-01 23:47 abv Description Updated
2019-11-02 10:38 abv Product Version => 7.4.0
2019-11-03 13:37 tizmaylo File Added:
2019-11-03 13:39 tizmaylo Note Added: 0088710
2019-11-03 13:39 tizmaylo Note Edited: 0088710
2019-11-03 13:41 tizmaylo Note Edited: 0088710
2019-11-03 13:41 tizmaylo Note Edited: 0088710
2019-11-03 13:42 tizmaylo Note Edited: 0088710
2019-11-03 21:52 git Note Added: 0088712
2019-11-04 14:53 git Note Added: 0088713
2019-11-04 15:24 abv Note Added: 0088714
2019-11-04 15:29 abv Note Added: 0088715
2019-11-04 15:29 abv Assigned To bugmaster => kgv
2019-11-04 15:29 abv Status new => resolved
2019-11-04 15:29 abv Steps to Reproduce Updated
2019-11-04 21:31 kgv Assigned To kgv => bugmaster
2019-11-04 21:31 kgv Status resolved => reviewed
2019-11-04 22:26 abv Relationship added related to 0031060
2019-11-07 10:43 bugmaster Note Added: 0088765
2019-11-07 10:43 bugmaster Status reviewed => tested
2019-11-07 10:56 bugmaster Test case number => Not required
2019-11-10 11:18 abv Changeset attached => occt master b31fbc83
2019-11-10 11:18 abv Assigned To bugmaster => abv
2019-11-10 11:18 abv Status tested => verified
2019-11-10 11:18 abv Resolution open => fixed
2019-11-10 11:41 git Note Added: 0088838
2020-12-02 16:22 emo Fixed in Version => 7.5.0
2020-12-02 17:12 emo Status verified => closed