vscode-linux-kernel
vscode-linux-kernel copied to clipboard
Visual Studio Code project template for Linux kernel source development and navigation.
Visual Studio Code project template for Linux kernel
Visual Studio Code project template for Linux kernel source development and navigation.
Preparation
Download and install Visual Studio Code
Install C/C++ extension for Visual Studio Code (In VSCode, Ctrl+Shift+X, search "C/C++")
Build your kernel first (important, it will generate some files that VSCode needed)
make <your-defconfig> # usually in the arch/<arch>/configs/ folder
make -j$(nproc)
VSCode setup
Copy .vscode to the linux kernel folder
Alternatively, you could use existing templates x86_64.vscode or arm64.vscode
Modify .vscode/c_cpp_properties.json to make IntelliSense work
-
Change <arch> to target architecture, for examples:
armfor ARM 32bitarm64for ARM 64bitx86for both x86 32bit and 64bit
-
Change <gcc-compile-path> to your gcc compile path, for examples:
/usr/bin/aarch64-linux-gnu-gccfor ARM 64bit/usr/bin/x86_64-linux-gnu-gccfor x86 64bit
-
Change <IntelliSenseMode> to the one of following:
linux-gcc-armlinux-gcc-arm64linux-gcc-x86linux-gcc-x64
Modify .vscode/tasks.json to make build tasks work (Optional)
-
Change <arch> to target architecture, for examples:
armfor ARM 32bitarm64for ARM 64bitx86for both x86 32bit and 64bit
-
Change <cross-compile> to your cross compile path, for examples:
aarch64-linux-gnu-for ARM 64bitx86_64-linux-gnu-for x86 64bit
-
Change defconfig to your own kernel config
Open with Visual Stdio Code
code .
Appendix
kernel build
-
Show kernel build commands and defines
make V=1 -
Specific kernel build output directory
make O=<output-dir> [extra_args] ... -
Change to kernel directory
make -C <kernel-src-dir> [extra_args] ... -
For more info
make help
VSCode
- Ctrl+P: Search files by name
- Ctrl+Shift+F: Search text in files
- F1, type
Restart IntelliSense For Active File(typeRestartand it should autosuggest)
References
- https://stackoverflow.com/a/64479335
- https://github.com/amezin/vscode-linux-kernel
- https://github.com/microsoft/vscode-cpptools/issues/5588
- https://stackoverflow.com/questions/5820303/how-do-i-force-make-gcc-to-show-me-the-commands