系统是Windows10 x64,已经安装好MinGW,版本是:
mingw32-gcc 5.3.0-3
mingw32-gcc-g++ 5.3.0-3
mingw32-gdb 7.6.1-1
现在我尝试编译并调试一个cpp代码test1.cpp:
#include <iostream>
using namespace std;
int main()
{
int a;
cout<<"HelloWorld!"<<endl;
cin>>a;
}
然后使用g++编译:
g++ -g test1.cpp -o test1.exe
通过,得到test1.exe,然后使用gdb调试:
gdb test1.exe
得到错误:
GNU gdb (GDB) 7.6.1
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "mingw32".
For bug reporting instructions, please see:
http://www.gnu.org/software/g......
"D:CppProjects/test1.exe": not in executable format: File format not recognized
(gdb)
请问如何解决?
后来发现之前用Anaconda装过旧版的MinGW,为了编译一些Python包。
先把环境变量删除,然后
conda uninstll mingw
,重启后重装MinGW,然后再设置环境变量。现在可以用了。