安裝操作
使用docker buildfile建立VSCode C/CPP docker Image
步驟
從Microsoft Dockerhub取得VSCode C/CPP docker
1
2# Docker buildfile
FROM mcr.microsoft.com/vscode/devcontainers/cpp:ubuntu-20.04安裝GCC/GDB toolchain, CMake
1
2
3
4# Docker buildfile
RUN apt-get --yes install build-essential
RUN apt-get --yes install gdb
RUN apt-get --yes install cmake使用範例
build.sh
安裝Image,安裝完成後,使用範例run.sh
執行container打開Vscode,選取Remote Explorer->Containers->Dev Containers->C(範例Container name),滑鼠右鍵點選Attach to Container
VsCode打開工作區File->Open Folder
編寫程式File->New File->main.c
1 |
|
- 執行程式Run->Run Without Debug
VSCode CMake
- 完成上面的Vscode C docker container
- 安裝VSCode CMake Extension,Extensions->Search->CMake, CMake Tools
- 設定CMake toolchain,View->Command Palette->CMake:Select a Kit->GCC
或者點選VSCode視窗最下方狀態列工具圖示 - 設定CMake Build Target,View->Command Palette->CMake:Set Build Target->Folder name[Executable]
或者點選VSCode視窗最下方狀態列三角形圖示 - 設定CMake Debug,View->Command Palette->CMake:Set Debug Target‘
- 執行程式Run->Run Without Debug
- 除錯程式Run->Debug,可在Debug console使用
-exec <gdb command>
進行除錯,也可透過GUI工具範例