课程官网:CS 144: Introduction to Computer Networking
这们课的实验是利用C++实现一个简易的TCP/IP协议栈。
官方给出了五种搭建实验环境的方式,这里我选择了第三种
参考我之前写的一篇Windows下搭建Linux开发环境的文章:基于VSCode+Clangd+lldb搭建Linux C++环境_cmake options: status bar visibility-CSDN博客
安装完WSL和Docker之后在CS144项目目录下配置.devcontainer的devcontainer.json和Dockerfile
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/cpp
{
"name": "CS144",
"build": {
"dockerfile": "Dockerfile"
},
// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "gcc -v",
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
# 使用最新的 Ubuntu 镜像作为基础镜像
FROM ubuntu:23.10
# 更新软件包列表并安装所需软件包,之后清理缓存
RUN apt-get update && apt-get install -y git cmake gdb build-essential clang \
clang-tidy clang-format gcc-doc pkg-config glibc-doc tcpdump tshark \
&& rm -rf /var/lib/apt/lists/*
然后Ctrl+Shift+P执行Dev Containers: Reopen in Container,就会创建容器,并用VSCode在容器中打开当前项目。
可以看到我这里已经成功进入容器中并且安装了实验要求的g++版本
至于如何调试,还是请参考
基于VSCode+Clangd+lldb搭建Linux C++环境_cmake options: status bar visibility-CSDN博客