如何解决-------未定义的引用`__chkstk_ms'-------关于mingw

2022-01-11 00:00:00 g++ mingw linker c++

我刚刚在 mingw 上安装了 gcc 和 g++.我编写了一个非常简单的hello world"程序来测试 g++ 编译器是否工作.代码:

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;
}

编译:

g++ Test.cpp

然后出现一些错误:

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

推荐答案

关于链接旧库的原始问题似乎已经解决,但我有相反的情况.我需要使用旧的 GCC 3.4 版本,所以我安装了 gcc-v3-core 包.然后在链接一个琐碎的源时立即出现原始错误.我发现 MinGW GCC 3.4 不能与 mingwrt > 3.20 一起使用,问题是 gcc-v3-core 包含不正确的 mingwrt 规范,允许使用最新版本.

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.

解决方法很简单:

mingw-get upgrade "mingwrt=3.20.*"

!更新!实际上,使用 mingwrt-3.20 链接器报告 C++ 代码的相同错误:

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

g++ hello.cpp

砰!

解决方案 2:

mingw-get upgrade "mingwrt=3.18.*"

最后一个似乎与 gcc-v3-g++ 一起工作的.

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

相关文章