C++学习之工具篇 三:Leetcode VSCode C++调试环境配置(Ubuntu篇)
1.基础环境配置
1.1 VSCode C++ 环境配置 Ubuntu
参考下方链接:
C++学习之工具篇 二:VSCode C++环境配置(Ubuntu篇)
1.2 Cmake安装
参考下方链接:
Ubuntu 安装Cmake
1.3 Node.js安装
apt安装:
非最新版本
sudo apt-get install nodejs
sudo apt-get install npm
源码安装:
git clone https://github.com/nodejs/node.git
cd node
$ sudo ./configure
$ make -j8
$ sudo make install
1.4 cJSON安装
git clone https://github.com/DaveGamble/cJSON.git
cd cJSON/
mkdir build
cd build/
cmake ..
make
sudo make install
执行完上述命令后,cJSON.h 头文件会安装在 /usr/local/include/cjson 目录下。libcjson.so库文件会安装在 /usr/local/lib 目录下。还需要将/usr/local/lib目录添加到 /etc/ld.so.conf文件中,然后执行 /sbin/ldconfig,否则程序在运行时会报 error while loading shared libraries: libcjson.so.1: cannot open shared object file: No such file or directory 错误。
sudo gedit /etc/ld.so.conf
2. Leetcode插件安装与配置
2.1 插件安装:
进入VSCode 扩展商店,搜索Leetcode,下载Leetcode
力扣官方版与DebugLeetCode
插件
2.2 插件配置
依次进入VSCode Settings -> Extensions -> Leetcode,将Endpoint修改为leetcode-cn
并配置WorkspaceFolder
2.3 登录LeetCode账号
依次点击 活动栏LeetCode插件图标 -> 侧边栏顶部 Sign in -> Account
3. 调试和提交
登录成功后,可在侧边栏看到Leetcode题目,选中题目,点击右下角CodeNow
进入编辑栏,输入程序;
设置好断点,可点击下方Debug
进行代码调试,调试成功后,即可点击Submit
进行代码提交
若调试过程中编译报错,可根据报错信息,排查问题,部分情况下需要增加头文件