Windows下安装mingw
Win10系统,安装mingw,想用g++\gcc编译器。
网上很多教程都是指引下载安装器的,但是下载后在线安装时却都出现下载的错误,所以无法安装成功。
参考mingw贴吧:https://tieba.baidu.com/p/5487544851?red_tag=1967781305
可以到页面:https://sourceforge.net/projects/mingw-w64/files/?source=navbar 下载离线安装包
根据贴吧帖子的建议,我下载了x86_64-posix-sjlj的压缩包,然后解压缩便得到了mingw64。
可以看到,这个是可以直接用的版本了
所以直接将/bin路径添加到环境变量中即可。
在命令行下,g++\gcc命令有效
这种方法快捷方便。
其他:
python setup.py build可以指定编译器,参考:https://stackoverflow.com/questions/16737260/how-to-tell-distutils-to-use-gcc/16737696#16737696
比如原来默认用的msvc,python setup.py build --compiler==mingw32则会改用mingw。
{ "version": "0.2.0", "configurations": [ { "name": "C++ Launch (GDB)", "type": "cppdbg", "request": "launch", "targetArchitecture": "x86", "program": "${workspaceRoot}\\${fileBasename}.exe", "miDebuggerPath":"D:\\mingw64\\bin\\gdb.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceRoot}", "externalConsole": true, "preLaunchTask": "g++" } ] }
5.创建一个tasks.json的配置文件
复制如下命令:
{ "version": "0.1.0", "command": "g++", "args": ["-g","-std=c++11","${file}","-o","${workspaceRoot}\\${fileBasename}.exe"], "problemMatcher": { "owner": "cpp", "fileLocation": ["relative", "${workspaceRoot}"], "pattern": { "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", "file": 1, "line": 2, "column": 3, "severity": 4, "message": 5 } } }
6.创建一个c_cpp_properties.json文件
并复制如下命令:
{ "configurations": [ { "name": "Win32", "includePath": [ "${workspaceRoot}", "D:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++", "D:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32", "D:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward", "D:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include", "D:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/tr1", "D:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include" ], "defines": [ "_DEBUG", "UNICODE", "__GNUC__=6", "__cdecl=__attribute__((__cdecl__))" ], "intelliSenseMode": "msvc-x64", "browse": { "path": [ "${workspaceRoot}", "D:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++", "D:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32", "D:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward", "D:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include", "D:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/tr1", "D:/Program Files/mingw-w64/x86_64-8.1.0-win32-seh-rt_v6-rev0/mingw64/x86_64-w64-mingw32/include" ] }, "limitSymbolsToIncludedHeaders": true, "databaseFilename": "" } ], "version": 3 }