Linking with -static-libstdc++ flag on MinGW 4.7.1

24,933

Solution 1

What does g++ --version say? I don't know the exact version when it was introduced, but -static-libstdc++ is a fairly recent addition. Before, you had to do something like -static -lstdc++ -dynamic. (If the compiler version is 4.7.1, this should not be a problem, but I don't know how MinGW versions map to the actual compiler version.)

Solution 2

I have not tested but try to separate as -static -libstdc++

Share:
24,933
topright gamedev
Author by

topright gamedev

Updated on January 10, 2020

Comments

  • topright gamedev
    topright gamedev over 4 years

    I try to compile (Allegro 5) on MinGW 4.7.1
    (using Code::Blocks 12.11 on Win 7)
    with compiler flags
    (write them in Project :: Linker settings :: Other linker settings):

    -static-libgcc
    -static-libstdc++

    Result:

    unrecognized command line option '-static-libstdc++'

    How to solve it?

  • topright gamedev
    topright gamedev over 11 years
    "cannot find -libstdc++"
  • topright gamedev
    topright gamedev over 11 years
    there is libstdc++.a in MinGW/lib/gcc/mingw32
  • James Kanze
    James Kanze over 11 years
    @toprightgamedev That's a good question. If there's no static library present, g++ can't link with it. (If there isn't, it's a bit silly, because I can't think of any case where you'd want to link the c++ standard library dynamicallyl)
  • topright gamedev
    topright gamedev over 11 years
    Yes, MinGW 4.7.1 (that was installed with Code::Blocks 12.11) has only libstdc++.a (searched by libstdc)
  • topright gamedev
    topright gamedev over 11 years
    I wanted to ask about it on Code::Blocks forums, but still waiting registration approval from admin... :]
  • topright gamedev
    topright gamedev over 11 years
    Wow, it says 4.6.2. I was sure it is 4.7.1. since there is mingw32-gcc-4.7.1.exe in distributive.
  • topright gamedev
    topright gamedev over 11 years
    There is also a directory gcc\mingw32\4.7.1 in the distributive. What a chaos.
  • James Kanze
    James Kanze over 11 years
    @toprightgamedev IIRC (it's been a while since I've installed MingW---my current PC is Linux), there are several versions you can choose from on the download page. But the surest statement, in this regard, is what g++ --version says, since it is compiled in. But as another poster said: find where the libraries are located, and see if there is a libstdc++.a present. If not, download one. And make sure it is in the same directory; if g++ finds a libstdc++.so in an earlier directory, it won't look any further.
  • topright gamedev
    topright gamedev over 11 years
    I've set explicit path to libstdc++.a and compile with the only "Other linker options": -static-libgcc. It says: undefined reference to _Unwind_Resume'` and undefined reference to __gxx_personality_v0' `
  • While-E
    While-E over 6 years
    Replace "-libstdc++" with "lstdc++" I would think...
  • SolarBear
    SolarBear almost 5 years
    The link is dead.
  • vgulkevic
    vgulkevic over 3 years
    This can also happen when using mingw with -static-libgcc -static-libstdc++ linker flags. Read more here: stackoverflow.com/questions/50779224/…