1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[メモ] Win11 wslc で devcontainer で Cコンパイル

1
Posted at

概要

  • wslのプレリリース版をインストール、wslc を使って、devcontainerでCをコンパイルしてみる。

環境

  • Windows 11 24H2
  • wsl (wsl.exe --update --pre-relaseにて更新)
  • VSCode 1.128.1
    C:\wsl --version
    WSL version: 2.9.4.0
    Kernel version: 6.18.35.2-1
    WSLg version: 1.0.79
    MSRDC version: 1.2.7214
    Direct3D version: 1.611.1-81528511
    DXCore version: 10.0.26100.1-240331-1435.ge-release
    Windows version: 10.0.26100.8655
    
    C:\>code --version
    1.128.1
    5264f2156cbcd7aea5fd004d29eaa10209155d66
    x64
    

手順

  1. WSL インストールと更新

    wsl --install
    wsl --update --pre-release
    
  2. VSCodeとエクステンション

    # エクステンション(Remote Development)
    code --install-extension ms-vscode-remote.vscode-remote-extensionpack
    
    • 設定 (CTRL + ,)
      • Userタブ
      • Extensions > Dev Containers : Docker Path
        • wslc
          image.png
  3. VSCodeを開いて、以下のファイルを作成

    プロジェクトフォルダ/
     ├─ .devcontainer/
     │   ├─ devcontainer.json
     │   └─ Dockerfile
     └─ src/
         └─ main.c
    
    • .devcontainer/devcontainer.json

      {
          "name": "GCC Dev Container",
          "build": {
              "dockerfile": "Dockerfile"
          },
          "customizations": {
              "vscode": {
                  "settings": {
                      "terminal.integrated.shell.linux": "/bin/bash"
                  },
                  "extensions": [
                      "ms-vscode.cpptools-extension-pack"
                  ]
              }
          },
          "remoteUser": "vscode"
      }
      
    • .devcontainer/Dockerfile

      # Use official Debian-based image with GCC
      FROM debian:stable-slim
      
      # Install GCC, G++, GDB, and make
      RUN apt-get update && \
          apt-get install -y build-essential gdb && \
          apt-get clean && rm -rf /var/lib/apt/lists/*
      
      # Create a non-root user for VS Code
      RUN useradd -ms /bin/bash vscode
      USER vscode
      WORKDIR /workspace
      
    • src/main.c

      #include <stdio.h>
      
      int main() {
          printf("Hello from GCC Dev Container!\n");
          return 0;
      }
      
  4. CTRL+P して、Dev Containers: Reopen in Container...

  5. main.cをひらいて、適当にブレイクポイントを貼って、[F5] でデバッグ
    image.png

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?