Visual Studio Code系列--CMake Tools使用说明

一、目的

        在linux系统上开发程序,一般都是使用vim+gcc+gdb进行的;但是为了开发效率我们也会使用Visual Studio Code进行开发,毕竟有界面的开发调试还是更加友好一些。

        老牌程序员肯定都知道make构建工具,但是其晦涩的语法还是难住不少初级开发者的。那么有没有一种更加方便的构建方式呢?

        答案是肯定的,我们可以使用CMake来进行构建,在Visual Studio Code上再配合CMake Tools工具真是如虎添翼。

        
​​​​​​​

 

二、实战

        参考资料

        Get started with CMake Tools on LinuxGet started with the CMake Tools Visual Studio Code extension on Linuxhttps://code.visualstudio.com/docs/cpp/CMake-linux#_select-a-kit

        1、安装Visual Studio Code
sudo apt updatesudo apt install software-properties-common apt-transport-https wget
sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main"
sudo apt install code
        2、确认开发环境
gcc -v

                 

        如果没有安装使用下面的命令安装 

sudo apt-get install gcc
sudo apt-get install build-essential gdb cmake

        确认cmake版本(尽量高于3.12.0)

cmake --version

 

        3、创建工程目录并安装visual studio code插件(C++ extension for VS CodeCMake Tools extension for VS Code

        在terminal下输入后打开visual studio code        

mkdir -p ~/workspace/work/test/cmakeQuickStart
cd ~/workspace/work/test/cmakeQuickStart
code .

         

        4、创建cmake hello world工程 

        通过组合按键(Ctrl+Shift+P)打开命令面板,然后输入cmake quick后回车

 

        输入工程名称helloWorld后回车

        选择编程语言

 

        选择编程类型(库或者可执行程序)

 

         

        再次打开命令面板输入cmake select a kit

 

        选择本地编译器 

        修改main.c文件

#include <stdio.h>

int main(int argc, char** argv){
    printf("Hello, from helloWorld!\n");
}

 

        5、编译 

        再次打开命令面板,输入cmake build

 

        编译完成后输出如下

 

        给程序添加断点(直接在代码行开头点击一下就会出现红点)

        6、调试

        再次打开命令面板,输入cmake debug

        进入调试窗口

 

         

        以上就是cmake tool的基本内容。 

        

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值