Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
676 views
in Technique[技术] by (71.8m points)

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

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 <iostream>
using namespace std;
int main()
{
cout << "hello world" << endl;
return 0;
}

Compile:

g++ Test.cpp

And then some errors appear:

D:/MinGW[Finished in 0.6s with exit code    1]/bin/../lib/gcc/mingw32/3.4.5/../../../../mingw32/lib/crt2.o: In function `_mingw_setargv':
D:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../mingw32/lib/libmingwex.a(glob.o): In function `glob_match':
i:pgiawsrcpkgmingwrt-4.0-1-mingw32-srcld/../mingwrt-4.0.0-1-mingw32-src/src/libcrt/misc/glob.c:733: undefined reference to `__chkstk_ms'
D:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../mingw32/lib/libmingwex.a(glob.o): In function `glob_strdup':
i:pgiawsrcpkgmingwrt-4.0-1-mingw32-srcld/../mingwrt-4.0.0-1-mingw32-src/src/libcrt/misc/glob.c:85: undefined reference to `__chkstk_ms'
D:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../mingw32/lib/libmingwex.a(glob.o): In function `glob_match':
i:pgiawsrcpkgmingwrt-4.0-1-mingw32-srcld/../mingwrt-4.0.0-1-mingw32-src/src/libcrt/misc/glob.c:841: undefined reference to `__chkstk_ms'
D:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../mingw32/lib/libmingwex.a(glob.o): In function `glob_strdup':
i:pgiawsrcpkgmingwrt-4.0-1-mingw32-srcld/../mingwrt-4.0.0-1-mingw32-src/src/libcrt/misc/glob.c:85: undefined reference to `__chkstk_ms'
D:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../../mingw32/lib/libmingwex.a(glob.o):i:pgiawsrcpkgmingwrt-4.0-1-mingw32-srcld/../mingwrt-4.0.0-1-mingw32-src/src/libcrt/misc/glob.c:85: more undefined references to `__chkstk_ms' follow
collect2: ld returned 1 exit status
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...