I'm trying to build elements library after few recent changes and can not make it link.
My toolchain:
- GCC 9.2.1 with MCF threads
- CMake 3.16.4
The commit that breaks the build: https://github.com/cycfi/elements/commit/104cef3cc19bf6f568b233a29679135a2c1f06ca
Relevant issue: https://github.com/cycfi/elements/issues/69
compiler flags: -DNOMINMAX -DWIN32_LEAN_AND_MEAN -D_UNICODE @CMakeFiles/Buttons.dir/includes_CXX.rsp -O3 -DNDEBUG -flto -fno-fat-lto-objects -std=gnu++17
error message:
[ 68%] Linking CXX executable Buttons.exe
cd /d D:\Files\C++\workspace_windows\elements_fork\build_fork\examples\buttons && "C:\Program Files\CMake\bin\cmake.exe" -E cmake_link_script CMakeFiles\Buttons.dir\link.txt --verbose=1
"C:\Program Files\CMake\bin\cmake.exe" -E remove -f CMakeFiles\Buttons.dir/objects.a
C:\mingw64\mingw64\bin\gcc-ar.exe cr CMakeFiles\Buttons.dir/objects.a @CMakeFiles\Buttons.dir\objects1.rsp
C:\mingw64\mingw64\bin\g++.exe -O3 -DNDEBUG -flto -fno-fat-lto-objects -mwindows -Wl,--whole-archive CMakeFiles\Buttons.dir/objects.a -Wl,--no-whole-archive -o Buttons.exe -Wl,--out-implib,libButtons.dll.a -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles\Buttons.dir\linklibs.rsp
C:/mingw64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.1/../../../../x86_64-w64-mingw32/bin/ld.exe: radio_button.cpp.obj (symbol from plugin):(.gnu.linkonce.t._ZN5cycfi8elements18basic_radio_buttonD1Ev[_ZThn208_N5cycfi8elements18basic_radio_buttonD1Ev]+0x0): multiple definition of `cycfi::elements::basic_radio_button::~basic_radio_button()'; main.cpp.obj (symbol from plugin):(.gnu.linkonce.t._ZN5cycfi8elements18basic_radio_buttonD1Ev[_ZThn24_N5cycfi8elements18basic_radio_buttonD1Ev]+0x0): first defined here
C:/mingw64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.1/../../../../x86_64-w64-mingw32/bin/ld.exe: radio_button.cpp.obj (symbol from plugin):(.gnu.linkonce.t._ZN5cycfi8elements18basic_radio_buttonD1Ev[_ZThn208_N5cycfi8elements18basic_radio_buttonD1Ev]+0x0): multiple definition of `non-virtual thunk to cycfi::elements::basic_radio_button::~basic_radio_button()'; main.cpp.obj (symbol from plugin):(.gnu.linkonce.t._ZN5cycfi8elements18basic_radio_buttonD1Ev[_ZThn24_N5cycfi8elements18basic_radio_buttonD1Ev]+0x0): first defined here
C:/mingw64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.1/../../../../x86_64-w64-mingw32/bin/ld.exe: radio_button.cpp.obj (symbol from plugin):(.gnu.linkonce.t._ZN5cycfi8elements18basic_radio_buttonD1Ev[_ZThn208_N5cycfi8elements18basic_radio_buttonD1Ev]+0x0): multiple definition of `non-virtual thunk to cycfi::elements::basic_radio_button::~basic_radio_button()'; main.cpp.obj (symbol from plugin):(.gnu.linkonce.t._ZN5cycfi8elements18basic_radio_buttonD1Ev[_ZThn24_N5cycfi8elements18basic_radio_buttonD1Ev]+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
Current observations:
- This is not an ODR violation problem.
- There is no diamond inheritance in the project.
- https://github.com/Xeverous/elements/tree/radio-button-build-debug builds but https://github.com/Xeverous/elements/tree/radio-button-build-debug-1 does not - the only difference is that for the
-1
branch I addedradio_button
objects to the example - https://stackoverflow.com/a/39256013/4818802 does not help (added the 3 commented lines for C++) - I have a reverse problem, I'm getting multiple definitions instead of a missing definition
- I tried the example code in attachment from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=47218 but it does not reproduce the problem
- The problem does not occur when building elements as a shared library
- The problem does not occur in CMake Debug build type
- The problem does not occur when LTO is not enabled
- All of affected classes that have this problem (after trying multple commits) have multiple inheritance