Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ld error: multiple definition of std::type_info::operator==(std::type_info const&) const #86

Closed
xparq opened this issue Sep 1, 2023 · 11 comments

Comments

@xparq
Copy link

xparq commented Sep 1, 2023

w64devkit 1.20.0, both 32/64 bit
(Tried to check with gcc12 in an older w64devkit which I also have here, but the project that triggers it depends on <format>.)

  • Does not happen with a stock Debian stable on WSL, using GCC 13.2 (installed from testing): g++ (Debian 13.2.0-2) 13.2.0
  • Same project builds clean with MSVC.
  • It's a single compilation unit.
  • I've been using doctest, but it didn't cause any issues earlier, and I don't think I've changed anything related.
  • I noticed this error a little while after adding std::regex stuff to the code. Not sure yet if that's related, I might test it out, if this doesn't seem familiar from elsewhere/upstream. (I've seen multiple vaguely similar reports for GCC etc., but the best matches were unanswered SO questions. [Answered one in the meantime.])
  • The project can afford -fno-rtti, so that's a viable workaround for me.
g++ -Wall --std=c++23 test.cpp
.../ld.exe: .../w64devkit/gcc13/64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/libstdc++.a(tinfo.o):tinfo.cc:
(.text$_ZNKSt9type_infoeqERKS_+0x0): multiple definition of `std::type_info::operator==(std::type_info const&) const';
...\Temp\ccOVUCq4.o:test.cpp:(.text$_ZNKSt9type_infoeqERKS_[_ZNKSt9type_infoeqERKS_]+0x0): first defined here
collect2.exe: error: ld returned 1 exit status

  (Edited for readability.)

@xparq
Copy link
Author

xparq commented Sep 1, 2023

Yup, confirmed; this single line can trigger it:

std::regex("");

Probably the regex compiler. (Just std::regex(); is not enough.)

Ahh, and I guess the Debian version is only immune to it for the extensive shared linking by default.

  • Update: Hmm, g++ -Wall -std=c++23 -static -static-libgcc -static-libstdc++ test.cpp still works on Debian. Maybe it's just fixed there. (No idea a single -static would be enough here, BTW... It's not for its MSVC equivalent.)

@skeeto
Copy link
Owner

skeeto commented Sep 1, 2023 via email

@xparq
Copy link
Author

xparq commented Sep 1, 2023

Thanks for the investigation. I wonder why the same static-linking command with c++23 can still work on Debian for the (~same) g++ version (lib32stdc++6 (13.2.0-2)).

(Tried to find something in /usr/share/doc/gcc-13-base/*Debian*, but couldn't.)

@Peter0x44
Copy link
Contributor

Peter0x44 commented Sep 1, 2023

I can't find any upstream reports for this bug.

I believe this has been reported upstream, albeit in a different context
I noticed it when I went to open a bug myself
https://gcc.gnu.org/PR110572

@skeeto
Copy link
Owner

skeeto commented Sep 1, 2023 via email

skeeto added a commit that referenced this issue Sep 1, 2023
For ABI compatability, prior to -std=c++23 this method uses old inline
semantics. Because libstdc++ itself is not compiled as -std=c++23, it is
incompatible with -std=c++23 code using this method, even including some
libstdc++ headers like regex. However, it isn't obvious unless libstdc++
is statically linked, as it is in w64devkit. It's always been statically
linked, so ABI compatability across w64devkit releases is less important.
@skeeto
Copy link
Owner

skeeto commented Sep 1, 2023 via email

@xparq
Copy link
Author

xparq commented Sep 1, 2023

I'm not even intelligent enough to build it from source. ;) But if you can link me up with a download, I'd happily start using it.

@Peter0x44
Copy link
Contributor

Peter0x44 commented Sep 1, 2023

I'm not even intelligent enough to build it from source.

If you have docker, check the README. It's not difficult, it does not require "intelligence".

skeeto added a commit that referenced this issue Sep 2, 2023
For ABI compatability, prior to -std=c++23 this method uses old inline
semantics. Because libstdc++ itself is not compiled as -std=c++23, it is
incompatible with -std=c++23 code using this method, even including some
libstdc++ headers like regex. However, it isn't obvious unless libstdc++
is statically linked, as it is in w64devkit. It's always been statically
linked, so ABI compatability across w64devkit releases is less important.
@xparq
Copy link
Author

xparq commented Sep 2, 2023

I know it's not difficult; that smiley for "intelligence" was meant to refer to the fact that I don't really have Docker.

skeeto added a commit that referenced this issue Sep 5, 2023
For ABI compatability, prior to -std=c++23 this method uses old inline
semantics. Because libstdc++ itself is not compiled as -std=c++23, it is
incompatible with -std=c++23 code using this method, even including some
libstdc++ headers like regex. However, it isn't obvious unless libstdc++
is statically linked, as it is in w64devkit. It's always been statically
linked, so ABI compatability across w64devkit releases is less important.
@xparq
Copy link
Author

xparq commented Feb 3, 2024

Oh, just noticed the (no longer that) new release! <3

Confirming that it has indeed fixed the issue for me, too.

(I don't know about your issue workflow preferences, but the fact that it has been kept open long after even releasing the fix suggests to me that it may be my job to verify it -- and then possibly even closing the thing? (Would be cool if GitHub supported issue workflow policies, at least in the form of just a link to the repo wiki; whatever... I'm just rambling, because I should be working otherwise. :) Thanks for the release!))

@skeeto
Copy link
Owner

skeeto commented Feb 3, 2024

Thanks for the followup, @xparq! I'll close this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants