• C++ 开发环境配置


    外接键盘

    设置

    Mac系统会默认把外接键盘的win映射成command,需要把外接键盘的alt键与win键功能交换。方法是使用"修饰键"完成这个交换 (对 外接 键盘操作)

    其他快捷键

    • command+L 定位到地址栏
    • command+tab 切换到下一个标签
    • command+2 切换到第2个标签
    • command+左右 定位到行首与行尾
    • command+上下 定位到文件头与文件尾
    • option (映射到alt上,又交换到win上)+左右 定位到上一个与下一个单词末尾
    • option (映射到alt上,又交换到win上)+command 光标变为十字型,拖动鼠标可以按列选中

    CLion 安装与配置

    使用Mac本地CLion与远程编译

    可参考官方安装教程或者clion 安装与配置。在Mac本地使用CLion进行日常开发,程序的编译与运行均需要登录远程开发机执行

    同步代码

    Mac本地CLion开发并同步代码到远程开发机,这种方法适合Mac本地开发环境 与 测试环境或线上环境不一致的情况,可以参考官方博客提供的方法:Stay local, let your IDE do remote work for you!。另外也可以参考以下操作自行配置:

    • 远程开发机中启动vsftpd服务
      • sudo yum install -y vsftpd; vi /etc/vsftpd/vsftpd.conf
      • centos7 启动vsftpd服务出错:listen=YES,anonymous_enable=NO, #listen_ipv6=YES, 使用了默认端口21,使用sudo service vsftpd start启动
    • CLion-tools-deployment-configure
      • CLion-tools-deployment-options-exclude items by name

    代码格式化

    通常使用clang-format进行格式化,对CLion2019.1之前版本在Mac本地操作步骤如下:

    • brew install clang-format
    • CLion中安装插件:Preferences-Plugin-File Watchers
    • CLion中配置插件,在文件被保存时自动执行格式化:Preferences-Tools-File Watchers下添加配置
      • program: clang-format
      • Arguments: -i $FileName$ --style=file
      • Output paths to refresh: $FileDir$
      • Trigger the watcher on external changes
    • CLion中配置外部工具:Preferences-Tools-External Tools
      • Tool Settings: 参考上述配置
    • CLion中配置外部工具快捷键,可以手动对当前文件执行clang-format格式化:Preferences-Keymap-External Tools

    格式化配置文件.clang-format示例:

    # Run manually to reformat a file:
    # clang-format -i --style=file <file>
    # find . -name '*.cpp' -o -name '*.h'  | xargs clang-format -i --style=file
    
    BasedOnStyle: Google
    

    远程调试

    有些情况debug一下还是很方便的,主要参考GDB Remote Debug,以下为主要步骤:

    • 远程开发机
      - yum install -y gdb-gdbserver
      - gdbserver IP:PORT executable
    • Mac本地CLion
      • CLion-Preferences-Build,Excution,Deployment-Toolchains 配置可用的 Debugger
      • Run-Edit Configarations-GDB Remote Debug 配置待调试目标的相关信息
        • GDB: Bundled GDB
        • target remote: IP:PORT
        • Symbol file: /local-path/build/executable
        • Sysroot: /local-path
        • Path Mappings: ```/remote-path /local-path

    注意 GDB Remote Debug 配置正确,以及本地的可执行文件需要与远程开发机中的可执行文件完全一致,否则调试过程中可能会出现一些问题如:

    • No source file named xxx.cpp
    • 断点不生效

    此外正确编写CMakeLists.txt(生成可远程调试的可执行文件)对远程debug也很重要,可参考:clion远程调试,示例如下:

    # Make 最低版本号要求
    cmake_minimum_required(VERSION 2.8)
    
    # 项目信息
    project(hello)
    
    # 指定源文件
    set(SOURCE_FILES main.cpp)
    
    set(CMAKE_SOURCE_DIR .)
    
    # 配置gdb调试
    set(CMAKE_BUILD_TYPE "Debug")
    set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g3 -ggdb -v")
    set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall -v")
    
    # 指定生成目标
    add_executable(hello ${SOURCE_FILES})
    

    插件及其他个性化配置

    • 取消namespace成员的缩进:Preferences-Editor-Code Style-Tabs and Indents-Indent members of namespace = 0
    • 变量声明处按等号对齐:Preferences-Editor-Code Style-Wrappings and Braces-Varable groups-Align in columns
    • 代码区按右键,选定column selection mode,可以按列选中代码
    • 函数/头文件跳转、生成代码(类、构造函数、接口的实现)、第三方主题等功能:需要 CLion 根据正确的 CMakeLists.txt 进行分析实现的
    • 第三方主题:参考Smart editor
    • 日常开发代码格式可参考:Google C++开源项目风格指南
    • 使用蛇形格式命名文件以及驼峰格式命名类:Preferences-Editor-Code Style-C/C++-New File Extensions

    使用远程 CLion 与编译

    待补充

    其他软件

    查找软件安装位置:右键->选项->在访达中显示;右键程序图标->显示包内容。如 clion 默认安装位置:/Applications/CLion.app/Contents/bin/clion.vmoptions

    iterm2

    • 有许多第三方主题插件,另外也可以使用自定义的主题,参考配置文件如下:
    ~ $pwd
    /var/root
    ~ $cat .bash_profile
    export BASH_SILENCE_DEPRECATION_WARNING=1
    
    #enables colorin the terminal bash shell export
    export CLICOLOR=1
    
    #setsup thecolor scheme for list export
    export LSCOLORS=gxfxcxdxbxegedabagacad
    
    #sets up theprompt color (currently a green similar to linux terminal)
    export PS1='[33[01;32m]u@h[33[00m]:[33[01;36m]w[33[00m]$     '
    #enables colorfor iTerm
    export TERM=xterm-256color
    
    alias wk="cd /Users/admin"
    alias ll="ls -lrtha"
    alias la='ls -lrtha'
    alias grep='grep --color'
    alias egrep='egrep --color'
    alias fgrep='fgrep --color'
    
    find_git_branch () {
    
    local dir=. head
    
    until [ "$dir" -ef / ]; do
    
    if [ -f "$dir/.git/HEAD" ]; then
    
    head=$(< "$dir/.git/HEAD")
    
    if [[ $head = ref: refs/heads/* ]]; then
    
    git_branch=" (${head#*/*/})"
    
    elif [[ $head != '' ]]; then
    
    git_branch=" → (detached)"
    
    else
    
    git_branch=" → (unknow)"
    
    fi
    
    return
    
    fi
    
    dir="../$dir"
    
    done
    
    git_branch=''
    
    }
    
    PROMPT_COMMAND="find_git_branch; $PROMPT_COMMAND"
    
    black=$'[e[1;30m]'
    
    red=$'[e[1;31m]'
    
    green=$'[e[1;32m]'
    
    yellow=$'[e[1;33m]'
    
    blue=$'[e[1;34m]'
    
    magenta=$'[e[1;35m]'
    
    cyan=$'[e[1;36m]'
    
    white=$'[e[1;37m]'
    
    normal=$'[e[m]'
    
    PS1="[33[0;31m]u [33[00;36m]W$yellow$git_branch [33[0;33m]$[e[1;37m]"
    

    普通用户按照如上内容配置 .bash_profile 后,打开item2,其配置是生效的,但sudo su到root后未生效,令root用户下主题也生效参考:

    • 如上 .bash_profile 内容追加到 /etc/bashrc 中
    • sudo -i 生效
    • sudo su 不生效
    • sudo su 之后 su - root 生效

    其他快捷键:

    • command + shift + i 同时向多个session发送命令

    ssh配置

    ww ~ $cat .ssh/config
    Host *
        ControlMaster auto
        ControlPath ~/.ssh/master-%r@%h:%p
    
    Host dev
        HostName xx.xx.xx.xx
        User root
        Port xx
        ServerAliveInterval 30
    

    访问trello

    • 申请vps服务器
    • 在vps服务器上搭建ss服务(ip+port)
    • ss客户端填写对应的ip+port+passwd
    • ss客户端选择PAC模式(自动识别)

    参考

    mac修改复制粘贴快捷键操作
    mac外接机械键盘
    OS X下机械键盘的设置和技巧
    Mac快捷键大全
    Intellij IDEA配置自动同步到FTP服务器
    Run and debug
    运行和调试
    GDB remote debugging, can't seem to find symbols
    GDB debugger problems - No source file named
    在 CLion 中进行调试
    配置CLion clang-format保存时自动格式化
    Iterm2多窗口同时输入命令
    macOS终端颜色的设定方法与说明:CLICOLOR与LSCOLORS
    iTerm2中ssh保持连接不断开

  • 相关阅读:
    XML-Signature 语法和签名
    ZooKeeper相关资料集锦
    分布式锁
    spring-boot 知识集锦
    Spring boot druid 多数据源配置
    常见 SQL 语句的加锁分析
    fastjson反序列化多层嵌套泛型类与java中的Type类型
    Clean ThreadLocals
    java AOP Before, After, AfterReturning, AfterThrowing, or Around 注解
    java 线程间的通信 (wait / notify / notifyAll)
  • 原文地址:https://www.cnblogs.com/wangzhiyi/p/9344786.html
Copyright © 2020-2023  润新知