cs50/libcs50: This is CS50's Library for C. (github.com)
1.安装VSCode + 子系统
子系统实际位置
C:\Users\用户名\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu22.04LTS_79rhkp1fndgsc\LocalState\rootfs\home
2.子系统更新
sudo apt-get update&&sudo apt-get upgrade&&sudo apt-get install -f
3.安装编译程序软件包
apt-get install build-essential
4.安装CS50辅助轮(先把文件仍到子系统)
//安装命令
sudo make install
//以下可省略
//检查静态库
ls /usr/local/lib/libcs50.a
//检查共享库文件
ls /usr/local/lib/libcs50.so
//验证库的可用性
ldconfig -p | grep cs50
5.安装WSL扩展
6.直接编译命令
make hello LDLIBS=-lcs50
7.创建Makefile文件
CC = cc
CFLAGS = -Wall -Wextra -Werror -std=c11
LDLIBS = -lcs50
# Generic rule to build an executable from a source file
%: %.c
$(CC) $(CFLAGS) $< -o $@ $(LDLIBS)
8.代码补全,需要配置MinGW环境变量,下载C/C++扩展,cs50.h cs50.c路径配置
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.22621.0",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64",
"compilerPath": "C:/Program Files/LLVM/bin/gcc.exe",
"configurationProvider": "ms-vscode.makefile-tools"
}
],
"version": 4
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"preLaunchTask": "C/C++: gcc.exe 生成活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files\\LLVM\\bin\\gdb.exe",//编译器位置
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
tasks.json
{
"tasks": [
{
"type": "shell",
"label": "C/C++: gcc.exe 生成活动文件",
"command": "C:\\Program Files\\LLVM\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"D:\\Codes\\CS50\\include\\cs50.c",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-I",
"D:\\Codes\\CS50\\include"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}


本文介绍了如何在Windows环境下,使用VSCode与Linux子系统来配置CS50编程环境。步骤包括安装VSCode、更新子系统、安装编译器、部署CS50库、安装WSL扩展、设置编译命令、创建Makefile及配置代码补全。
1090

被折叠的 条评论
为什么被折叠?



