How to solve -------undefined reference to `__chkstk_ms'-------on mingw

前端 未结 6 844
终归单人心
终归单人心 2020-12-04 00:23

I have just install gcc and g++ on mingw. I wrote a very simple \"hello world\" program to test if the g++ compiler worked. Code:

#include 
u         


        
相关标签:
6条回答
  • 2020-12-04 00:50

    The orig problem seems solved regarding linking against old libs, but I have opposite case. I need to work with older GCC 3.4 version, so I installed gcc-v3-core package. Then orig errors immediately appear when linking a trivial source. I found out that MinGW GCC 3.4 cannot work with mingwrt > 3.20 and the problem is that gcc-v3-core contains incorrect mingwrt spec, allowing newest vesions.

    The solution is simple:

    mingw-get upgrade "mingwrt=3.20.*"
    

    !Update! Actually with mingwrt-3.20 linker reports same errors for C++ code:

    g++ hello.cpp
    

    BAM!

    Solution 2:

    mingw-get upgrade "mingwrt=3.18.*"
    

    the last one that seems to work with gcc-v3-g++.

    0 讨论(0)
  • 2020-12-04 00:53

    This might be a "modern" answer to the original question: You may miss the stdc++ and gcc library in MinGW, have to link them by yourself manually.

    0 讨论(0)
  • 2020-12-04 00:54
    • To compile a .cpp file you have to issue the following command for it to compile. I suggest you use gcc instead of g++, they both work either way.
    • gcc -c Test.cpp -o Test.exe
    • Or with g++
    • g++ -c Test.cpp -o Test.exe
    0 讨论(0)
  • 2020-12-04 00:55

    Simply install and run the GCC in Windows XP.

    I tested exactly the same MinGW binaries (based on GCC-3.4.5) in Windows_10_x64_b1607 and Windows_XP_SP3. Windows 10 generates __chkstk_ms errors, but in Windows XP everything is fine.

    0 讨论(0)
  • 2020-12-04 00:57

    Here's an authoritative answer, from a MinGW project administrator.

    Your problem arises because you continue to use an obsolete, (no longer maintained; no longer supported), version of GCC. Current versions of mingwrt are compiled using GCC-4.x, (I used GCC-4.8.2 for mingwrt-3.21 and its descendants), and this introduces the dependencies on __chkstk_ms, (which is provided by libgcc -- a GCC-4.x specific library, which is incompatible with GCC-3.x).

    FWIW, I can reproduce your issue if I install a GCC-4.8.2 built mingwrt-3.21.1 into a GCC-3.4.5 installation. By the same token, I can also successfully use mingwrt-3.21.1 with GCC-3.4.5, if I build it with that same version of GCC.

    Thus, for an authoritative answer: if you must continue to use an obsolete GCC version, you need to be prepared to rebuild all associated libraries, using that same obsolete compiler.

    0 讨论(0)
  • 2020-12-04 01:05

    I had a similar problem, which arose because I foolishly installed a newer version into an old installation. The fix was obvious, I backed up my old installation, then deleted it and done a fresh install. Everything compiled perfectly. Old habits die hard I guess. ;)

    0 讨论(0)
提交回复
热议问题