VSCode-C语言环境多文件一键运行
目录
VSCode C语言环境(多文件一键运行)
配置CMake
下载CMake并安装
https://cmake.org/download/配置mingw64
https://github.com/niXman/mingw-builds-binaries/releasesi686-14.2.0-release-mcf-dwarf-ucrt-rt_v12-rev1.7z
i686-14.2.0-release-posix-dwarf-msvcrt-rt_v12-rev1.7z
i686-14.2.0-release-posix-dwarf-ucrt-rt_v12-rev1.7z
i686-14.2.0-release-win32-dwarf-msvcrt-rt_v12-rev1.7z
i686-14.2.0-release-win32-dwarf-ucrt-rt_v12-rev1.7z
x86_64-14.2.0-release-mcf-seh-ucrt-rt_v12-rev1.7z
x86_64-14.2.0-release-posix-seh-msvcrt-rt_v12-rev1.7z
x86_64-14.2.0-release-posix-seh-ucrt-rt_v12-rev1.7z
x86_64-14.2.0-release-win32-seh-msvcrt-rt_v12-rev1.7z
x86_64-14.2.0-release-win32-seh-ucrt-rt_v12-rev1.7z这里有很多版本:
x86_64和i686是64位和32位的区别,seh和dwarf分别专用于此posix和win32是线程模型的区别,posix跨平台,win32性能好ucrt和msvcrt是运行时库的区别,ucrt只有win10+支持
现在都是win10以上的系统了,肯定选
x86_64-14.2.0-release-posix-seh-ucrt-rt_v12-rev1.7z
下载解压后,将
bin
文件夹添加到环境变量,其中包括了
gcc
和
make
配置VSCODE
安装
CMake Tools
插件
在工作区创建两个源文件
main.c
#include <stdio.h>
extern void test_cmake();
int main(int argc, char const *argv[])
{
test_cmake();
printf("Hello, World!\n");
return 0;
}test_cmake.c
#include "stdio.h"
void test_cmake()
{
printf("Hello from test_cmake\n");
}在工作区创建CMakeLists.txt,输入如下内容后,左下角就会生成调试和运行按钮
cmake_minimum_required(VERSION 3.10)
# Set the project name
project(TEST_C)
# Add all .c files in the current directory
file(GLOB SOURCES "*.c")
# Add an executable
add_executable(main ${SOURCES})