惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园_首页
H
Help Net Security
腾讯CDC
宝玉的分享
宝玉的分享
H
Hackread – Cybersecurity News, Data Breaches, AI and More
L
LangChain Blog
爱范儿
爱范儿
T
The Blog of Author Tim Ferriss
J
Java Code Geeks
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
MyScale Blog
MyScale Blog
Engineering at Meta
Engineering at Meta
N
Netflix TechBlog - Medium
D
Docker
V
V2EX
Last Week in AI
Last Week in AI
G
Google Developers Blog
IT之家
IT之家
C
Check Point Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 聂微东

博客园 - CHHC

跨平台桌面应用(内嵌 Web 界面 + Go RESTful API 服务) Dify 网页爬虫 Ai常用工具 Dify公司内部知识库权限隔离 智能体:OA行政助手 dify4: test-doc dify3: test-api dify2: test-image dify1: test-local-ollama 访问本地大模型 docker + dify + ollma 安装与配置 dify使用 eSIM SGP32 IPAd 适配移远EC200A OpenCPU 公钥解析 eSIM SGP32 自建符合GSMA规范的eIM平台(支持SGP32及SGP22卡接入) eSIM SGP32 eIM GSMA转码器(支持net及java) eSIM SGP32 证书 eSIM SGP32 生成eUICC所需的配置数据 eSIM SGP32 EuiccPackage包eimSignature和euiccSignEPR生成及校验 eSIM SGP32/SGP22 EUICC.SDK - IPAd RTSPShape-包含服务端及客户端 树莓派安装与配置 NetCore树莓派桌面应用程序 C#解析TLV数据(der -> asn1) golang 项目依赖备份 SGP32笔记 SoftSIM - swSIM eSIM SGP.22 LPA程序开发 - 协议解析 eSIM SGP.22 LPA程序开发 - 实现功能 PGP文件加解密 网关开发笔记
vscode配置c/c++环境
CHHC · 2025-12-05 · via 博客园 - CHHC

VS Code 配置 C/C++ 编程运行环境(保姆级教程)_vscode配置c++环境-CSDN博客

1. 安装vscode,安装插件(C/C++ Runner  C/C++ Build Task C/C++ C/C++ Extension Pack CMake CMake Tools)

2. 安装MinGW-W64,添加到环境变量,mingw32-make.exe重命名为make

gcc --version
g++ --version
gdb --version

 main.c

#include <stdio.h>
#include "max.h"

int main()
{
    for (int i = 0; i < 2; i++)
        printf("Hello Grayson~%d\n", i); 

    int a = 10;
    int b = 30;
    int c = findMaxNum(a, b);
    printf("%d\n", c);

    return 0;
}

max.c

#include "max.h"

int findMaxNum(int num1, int num2)
{
    return num1 > num2 ? num1 : num2;
}

max.h

#ifndef __MAX_H__
#define __MAX_H__
#include <stdio.h>

int findMaxNum(int num1, int num2);

#endif // __MAX_H__

【编译调试】

vscode: Code Runner直接编译运行多个C程序

解决引用了库文件但提示找不到调用函数的问题:

image

image

image

 点击在settings.json中编辑后,打开settings.json文件如图,找到executorMap设置项,在其中c程序对应的一行,修改其中的gcc $filename为gcc *.c

image

 修改保存之后,再点击Code Runner运行按钮,可以直接编译运行了

image

Debug调试

按 Ctrl+Shift+P,输入并选择 “任务:配置任务”。选择 “从模板创建 tasks.json 文件” -> “Others”。

tasks.json


{

  "version": "2.0.0",

  "tasks": [

    {

      "type": "cppbuild",

      "label": "Build All C Files", // 任务名称

      "command": "gcc", // 或你的编译器路径,如 "C:/MinGW/bin/gcc.exe"

      "args": [

        "-g", // 生成调试信息

        "-Wall", // 开启警告

        "*.c", // 关键:编译当前目录下所有.c文件[citation:9]。也可明确列出,如 "main.c", "helper.c"

        "-o", // 指定输出文件名

       

"${workspaceFolder}/bin/helloworld.exe" // 生成的可执行文件路径

      ],

      "options": {

        "cwd": "${workspaceFolder}" // 在项目根目录执行命令

      },

      "problemMatcher": ["$gcc"],

      "group": {

        "kind": "build",

        "isDefault": true

      }

    }

  ]

}

launch.json

{

  "version": "0.2.0",

  "configurations": [

    {

      "name": "(gdb) Launch",

      "type": "cppdbg",

      "request": "launch",

     

"program": "${workspaceFolder}/bin/helloworld.exe",

      "args": [],

      "stopAtEntry": false,

      "cwd": "${workspaceFolder}",

      "environment": [],

      "externalConsole": false,

      "MIMode": "gdb",

      "miDebuggerPath": "gdb",

      "setupCommands": [

        {

          "description": "Enable pretty-printing",

          "text": "-enable-pretty-printing",

          "ignoreFailures": true

        }

      ],

      "preLaunchTask": "Build All C Files"

    },

    {

      "name": "C/C++ Runner: Debug Session",

      "type": "cppdbg",

      "request": "launch",

      "args": [],

      "stopAtEntry": false,

      "externalConsole": true,

      "cwd": "f:/demo2025/c/helloworld",

      "program": "f:/demo2025/c/helloworld/build/Debug/outDebug",

      "MIMode": "gdb",

      "miDebuggerPath": "gdb",

      "setupCommands": [

        {

          "description": "Enable pretty-printing for gdb",

          "text": "-enable-pretty-printing",

          "ignoreFailures": true

        }

      ]

    }

  ]

}

配置后,按 Ctrl+Shift+B 即可执行 make 命令来构建项目

image

【发布】

Makefile编译

CC = gcc
CFLAGS = -Wall -Wextra -std=c99 -I.
TARGET = main.exe
OBJS = main.o max.o

# 检测操作系统
ifeq ($(OS),Windows_NT)
    RM = del /Q
    TARGET := $(TARGET)
    RM_CMD = if exist $(1) $(RM) $(1)
else
    RM = rm -f
    RM_CMD = $(RM) $(1)
endif

all: $(TARGET)

$(TARGET): $(OBJS)
    $(CC) $(CFLAGS) -o $@ $(OBJS)

main.o: main.c max.h
    $(CC) $(CFLAGS) -c main.c

max.o: max.c max.h
    $(CC) $(CFLAGS) -c max.c

clean:
    $(call RM_CMD,$(TARGET))
    $(call RM_CMD,main.o)
    $(call RM_CMD,max.o)
    @echo Clean completed!

.PHONY: all clean

make clean
make

使用 CMake 自动生成 Makefile

CMakeLists.txt

# 指定CMake最低版本要求
cmake_minimum_required(VERSION 3.10)
# 定义项目名称
project(helloworld)
# 设置C标准
set(CMAKE_C_STANDARD 11)
# 生成可执行文件,列出所有源文件
add_executable(helloworld main.c max.c max.h)

Makefile编译

F:\demo2025\c\helloworld>rmdir /s /q build 

F:\demo2025\c\helloworld>mkdir build

F:\demo2025\c\helloworld>cd build

F:\demo2025\c\helloworld\build>cmake -G "MinGW Makefiles" ..
-- The C compiler identification is GNU 15.2.0
-- The CXX compiler identification is GNU 15.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: D:/Program_Files/mingw64/bin/cc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: D:/Program_Files/mingw64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (8.6s)
-- Generating done (0.0s)
-- Build files have been written to: F:/demo2025/c/helloworld/build

F:\demo2025\c\helloworld\build>make
[ 33%] Building C object CMakeFiles/helloworld.dir/main.c.obj
[ 66%] Building C object CMakeFiles/helloworld.dir/max.c.obj
[100%] Linking C executable helloworld.exe
[100%] Built target helloworld

F:\demo2025\c\helloworld\build>helloworld.exe
Hello Grayson~0
Hello Grayson~1
30