配置VScode c语言环境
整理:Visual Studio Code (vscode) 配置C、C++环境/编写运行C、C++(主要Windows、简要Linux)
mingw官网
windows下安装MinGW及C++的环境配置
cygwin官网
cygwin完全安装步骤方法(组图)
window 下完全卸载Cygwin最简单方法
cygwin安装、卸载及一些问题解决
彻底删除Cygwin
官网下载mingw-get-setup.exe
,
默认安装,在Basic Setup
下选中下面,然后菜单Installation > Apply Changes
,开始安装,默认安装路径在C:\MinGW
,
添加环境变量,
测试,打开PowerShell,第一次错误是因为曾被不同版本的mingw编译过,先执行clean再编译,
PS C:\dog\program\cgi\cgic207> mingw32-make
gcc capture.o -o capture -L./ -lcgic
capture.o: file not recognized: file format not recognized
collect2.exe: error: ld returned 1 exit status
Makefile:25: recipe for target 'capture' failed
mingw32-make: *** [capture] Error 1
PS C:\dog\program\cgi\cgic207> mingw32-make clean
rm -f *.o *.a cgictest.cgi capture cgicunittest
PS C:\dog\program\cgi\cgic207> mingw32-make
gcc -g -Wall -c -o cgic.o cgic.c
rm -f libcgic.a
ar rc libcgic.a cgic.o
ranlib libcgic.a
gcc -g -Wall -c -o cgictest.o cgictest.c
gcc cgictest.o -o cgictest.cgi -L./ -lcgic
gcc -g -Wall -c -o capture.o capture.c
gcc capture.o -o capture -L./ -lcgic
添加msys shell终端快捷方式,
选择更改图标,
挂载本地盘,注意c:
这里必须小写字母,
qinge@DESKTOP-4KV9JL3 ~
$ mkdir dog
qinge@DESKTOP-4KV9JL3 ~/dog
$ mount c:/dog /home/qinge/dog
#include
int main(int argc, char **argv)
{
printf("hello\n");
return 0;
}
在VSCode终端中用gcc编译,执行,
PS C:\dog\program\cgi\helloworld> gcc -g helloworld.c -o helloworld.exe
PS C:\dog\program\cgi\helloworld> ls
目录: C:\dog\program\cgi\helloworld
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2019/3/5 20:41 94 helloworld.c
-a---- 2019/3/5 20:43 54202 helloworld.exe
PS C:\dog\program\cgi\helloworld> .\helloworld.exe
hello
点击左边栏调试按钮,配置launch.json
,选择C++ (GDB)
,
自动新建launch.json
,修改program
,miDebuggerPath
,
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/helloworld.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Qt\\Qt5.12.0\\Tools\\mingw730_64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
官网下载,默认安装,这儿选第一个,不是第二个。
按目录展示软件包,选择Devel下的make,gcc-core,gcc-g++,autoconf,autogen,automake,binutils,libtool,cygwin32-w32api-headers,cygwin32-w32api-runtime,pkg-config,支持c语言的编译,否则会出现头文件找不到的毛病,添加环境变量,Cygwin本地盘自动挂载在/cygdrive
,Cygwin程序运行需要的动态库在*\cygwin64\bin
中,将cygwin1.dll拷贝到应用程序同目录才可以执行,注意,对于已经安装mingw,配置了环境变量,cygwin会加载mingw的命令集,没有安装make软件包,也找到了make命令,其实那是mingw的,
qinge@DESKTOP-4KV9JL3 ~
$ ls /cygdrive
c