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

Linking error "duplicate symbol: std::type_info::operator==" on static build with MinGW #3042

Closed
o-kos opened this issue Sep 29, 2021 · 6 comments
Labels
platform: mingw related to MinGW solution: invalid the issue is not related to the library

Comments

@o-kos
Copy link

o-kos commented Sep 29, 2021

json 3.9.1 + MinGW 10.3.0 + Clang 12.0.0 x86
Link error on build test example with "--static" flag when use dump() method:

warning: failed to compute relocation: IMAGE_REL_I386_REL32, Invalid data was encountered while parsing the file
lld-link: error: duplicate symbol: std::type_info::operator==(std::type_info const&) const
>>> defined at C:/tools/msys64/mingw32/include/c++/10.3.0/typeinfo:121
>>>            objects.a(main.cpp.obj)
>>> defined at libstdc++.a(tinfo.o)
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

without the "--static" flag, the build finishes successfully.

Can you provide a small but working code example?

#include "nlohmann/json.hpp"
using json = nlohmann::json;

int main()
{
    json j;
    j["pi"] = 3.141;
    std::string s = j.dump(2);
}

If comment string with j.dump(), build is ok.

@nlohmann
Copy link
Owner

I am not sure how this issue is related to this library if it mentions a duplicate symbol in namespace std... 🤔

@o-kos
Copy link
Author

o-kos commented Sep 30, 2021

But this error exists only when using .dump () method and only in static build mode.

@nlohmann
Copy link
Owner

nlohmann commented Oct 1, 2021

I understand - but maybe it's just triggering some bug inside the compiler. Anyway, I see if I can reproduce this in the CI.

@nlohmann nlohmann added the platform: mingw related to MinGW label Oct 1, 2021
@o-kos
Copy link
Author

o-kos commented Oct 1, 2021

I looked inside the json.hpp code and reproduced problem without json library:

#include <memory>

class output_string_adapter
{
public:
    output_string_adapter() = default;
};

int main()
{
    std::make_shared<output_string_adapter>();
}

If last code line don't consist std::make_shared - no error. Do you have anything version about this?

@nlohmann nlohmann added solution: invalid the issue is not related to the library and removed kind: bug labels Oct 3, 2021
@nlohmann
Copy link
Owner

nlohmann commented Oct 3, 2021

Thanks for checking back!

@nlohmann nlohmann closed this as completed Oct 3, 2021
@maveric2
Copy link

maveric2 commented Jul 3, 2023

See the issue too, but cannot reproduce it with the reduced example (without json). I get the error within another context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: mingw related to MinGW solution: invalid the issue is not related to the library
Projects
None yet
Development

No branches or pull requests

3 participants