Vscode之搭建C++环境

第一步下载msys2

http://www.msys2.org/

第二步安装完,修改配置文件

参考如下:

https://mirrors.tuna.tsinghua.edu.cn/help/msys2/

 

1. \etc\pacman.d\mirrorlist.mingw32
2. \etc\pacman.d\mirrorlist.mingw64
3. \etc\pacman.d\mirrorlist.msys

增加配置

# in mirrorlist.msys
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/msys/$arch
# in mirrorlist.mingw64
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/x86_64
# in mirrorlist.mingw32
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/i686

第三步:执行更新

运行 pacman -Syu

下载工具包这一部分就是纯粹的pacman知识了,涉及的指令有:
pacman -Sy 更新软件包数据
pacman -Syu 更新所有
pacman -Ss xx 查询软件xx的信息
pacman -S xx 安装软件xx 

更新完结果如下:

 第四步:安装gcc

 查询gcc

pacman -Sl |grep gcc

 安装

 pacman -S msys/gcc

第五步 gdb的安装

 pacman -Sl |grep gdb

 pacman -S msys/gdb

第六步:测试安装情况

输入gcc -v

 输入make -v

 输入gdb -v

 

第七步 VScode的安装

https://code.visualstudio.com/docs/languages/cpp

 

 

 ******************************20190620晚 一直在windows下无法进行调试,决定转战linux*************

https://code.visualstudio.com/docs/setup/linux#_rhel-fedora-and-centos-based-distributions

 

*********

安装gcc

yum install centos-release-scl
yum install devtoolset-4-toolchain
scl enable devtoolset-4 bash
gcc --version

scl enable devtoolset-3 bash只是临时覆盖系统原有的GCC引用,

(一直不成功的方法如果想永久覆盖,可在root/.bashrc文件中添加source /opt/rh/devtoolset-3/enable)

后来换成修改环境变量如下:在home下面哦

结果如下:

 

安装cmake

第一步:直接到官网下载cmake

https://cmake.org/files/v3.15/

解压到这里

修改系统环境变量

在使用

source ~/.bashrc

使环境变量生效。

再查看版本

cmake --version

 设置cmake的kit

输入view----》Command Palette ---》CMake:Edit user-local kit

输入如下内容

[
  {
    "name": "gcc 4.8.5",
    "compilers": {
      "C": "/usr/bin/x86_64-redhat-linux-gcc",
      "CXX": "/usr/bin/x86_64-redhat-linux-g++"
    },
    "keep": true
  }
]

就可以编译啦;

 编译结果如下:

 一共安装了4个插件,也截个图记录下

 *******************使用cmake生成的文件不带调试信息*************

https://vector-of-bool.github.io/docs/vscode-cmake-tools/index.html

后来重启一下,好了,然后删掉重新再生成,有不行了,所以我不准备纠结这个问题了

另外,可以调试配合make一起使用,配置如下

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "gcc build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${command:cmake.launchTargetPath}",
            "args": [],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

上一个可以调试的图:

 好艰辛。。。。。。。。。。。。

明天开始研究C++11的语法了。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值