DiscussionsIssue archiveOCCT:Configuration

Archived issue #0031680

Configuration - Compilation Fails With G++ 10.1, LD 2.34 and Link-Time Optimization

CommunityOCCT:Configurationclosed3 public notes

Search issues

Description

When building OCCT with g++ 10.1, ld 2.34 and link-time optimization (-flto) using Mingw-w64 on Windows 10, I get the following error:

C:/mingw-w64-10.1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: LDOM_OSStream.cxx.obj (symbol from plugin):(.gnu.linkonce.t._ZTV13LDOM_OSStream[_ZTV13LDOM_OSStream]+0x0): multiple definition of `VTT for LDOM_OSStream'; PCDM_ReadWriter.cxx.obj (symbol from plugin):(.gnu.linkonce.t._ZTV13LDOM_OSStream[_ZTC13LDOM_OSStream0_So]+0x0): first defined here
C:/mingw-w64-10.1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: LDOM_OSStream.cxx.obj (symbol from plugin):(.gnu.linkonce.t._ZTV13LDOM_OSStream[_ZTV13LDOM_OSStream]+0x0): multiple definition of `vtable for LDOM_OSStream'; PCDM_ReadWriter.cxx.obj (symbol from plugin):(.gnu.linkonce.t._ZTV13LDOM_OSStream[_ZTC13LDOM_OSStream0_So]+0x0): first defined here
C:/mingw-w64-10.1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: LDOM_OSStream.cxx.obj (symbol from plugin):(.gnu.linkonce.t._ZTV13LDOM_OSStream[_ZTV13LDOM_OSStream]+0x0): multiple definition of `construction vtable for std::ostream-in-LDOM_OSStream'; PCDM_ReadWriter.cxx.obj (symbol from plugin):(.gnu.linkonce.t._ZTV13LDOM_OSStream[_ZTC13LDOM_OSStream0_So]+0x0): first defined here


I have found more "multiple definition" errors with this tool combination, but I do not fully understand the reason. See https://stackoverflow.com/questions/62150048/why-does-g-10-1-complain-about-a-named-lambda-in-a-header-file-and-others-do-n for another example. These errors haven't been there up to g++ 9.2 (I do not know the corresponding ld version number anymore), but appear here from g++ 10.1 on.

This post: https://stackoverflow.com/a/57504289/2492801
explains how to force vtable generation. According to my understanding the vtable of LDOM_OSStream is generated in more than one compilation unit, since that class does not have a non-inline virtual function.

Following the cited post, I propose to add a non-inline virtual destructor. Indeed this solves the compilation problems here.

Steps to reproduce

Not required

Public activity

3 archived notes

Participants are labeled by their role within this record.

01Commenter 2
Branch [archived branch] has been created by Author.

[revision removed]


Detailed log of new commits:

Author: Benjamin Bihler
Date: Tue Jul 21 13:37:03 2020 +0200

    0031680: Configuration - Compilation Fails With G++ 10.1, LD 2.34 and Link-Time Optimization
    
    Added a non-inline empty virtual destructor to LDOM_OSStream to force vtable generation in one
    translation unit only.
02Commenter 1
Combination -
OCCT branch : [archived branch]
master SHA - [revision removed]
[revision removed]
Products branch : [archived branch] SHA - [revision removed]
was compiled on Linux, MacOS and Windows platforms and tested in optimize mode.

Number of compiler warnings:
No new/fixed warnings

Regressions/Differences/Improvements:
No regressions/differences

CPU differences:
Debian80-64:
OCCT
Total CPU difference: 17271.39000000011 / 17230.04000000007 [+0.24%]
Products
Total CPU difference: 800.6699999999917 / 791.7399999999936 [+1.13%]
Windows-64-VC14:
OCCT
Total CPU difference: 18742.140625 / 18745.390625 [-0.02%]
Products
Total CPU difference: 1329.234375 / 1321.390625 [+0.59%]


Image differences :
No differences that require special attention

Memory differences :
No differences that require special attention
03Commenter 2
Branch [archived branch] has been deleted by Participant.

[revision removed]