1.clion安装
1.1 clion软件包下载
- 根据自己系统选择对应安装包:clion下载地址
1.2 clion软件包安装
- (1) windows:直接双击安装,这个没什么好说的
- (2) Linux:
# 1.软件包解压
>> tar -xf [clion安装包]
# 2.解压路径重命名
>> mv [clion解压文件] clion
# 3.获取当前路径
>> cd clion && pwd
/home/mirror/software/clion/bin
# 4.配置环境变量
# ~/.bashrc或~/.zshrc
>> vim ~/.zshrc
export CLION_PATH=/home/mirror/software/clion/bin
export PATH=$PATH:$CLION_PATH
alias clion = clion.sh
1.3 clion破解
- (1) 破解包:JetBrains 全家桶激活(2024最新).zip ,提取码: 7bp2
- (2) 使用方法:破解包解压出来文件中有包含
2.clion配置
- [1] 设置字体为Consolas
"Editor" -> "Font" -> Font: "Consolas"
- [2] 设置文件和代码模板
# C文件头
"Editor" -> "File and Code Templates" -> "Includes" -> "C File Header"
/*
* @Description:
* @Author: chenjingyu
* @Date: ${YEAR}-${MONTH}-${DAY} ${HOUR}:${MINUTE}:${SECOND}
* @FilePath: ${FILE_NAME}
*/
# C头文件
"Editor" -> "File and Code Templates" -> "Files" -> "C Header File"
#parse("C File Header.h")
#pragma once
# C源文件
"Editor" -> "File and Code Templates" -> "Files" -> "C Source File"
#parse("C File Header.h")
#if (${HEADER_FILENAME})
#[[#include]]# "${HEADER_FILENAME}"
#end
# C++类的头文件
"Editor" -> "File and Code Templates" -> "Files" -> "C++ Class Header"
#parse("C File Header.h")
#pragma once
class ${NAME} {
};
# C++类
"Editor" -> "File and Code Templates" -> "Files" -> "C++ Class"
#parse("C File Header.h")
#[[#include]]# "${HEADER_FILENAME}"
- [3] 设置在线模板
"Editor" -> "Live Templates" -> "C/C++" -> "+"
Abbreviation: "name" Description: "namesapace"
Template text:
namespace {
}
"define" -> 勾选"C++" -> "Apply"
Abbreviation: "main" Description: "main"
Template text:
int main(int argc, char *argv[]) {
return 0;
}
"define" -> 勾选"C++" 和"C" -> "Apply"
- [4] 设置代码风格
"Editor" -> "Code Style" -> "C/C++" -> "Tabs and Indents"
Tab size: 2
Indent: 2
Continuation indent: 2
勾选 Keep indents on empty lines
Label indent: 0
Indent in lambdas: 2
Indent members of plain structures: 2
Indent members of classes: 2
Indent visibility keywords in class/structure: 0
Indent members of namespace: 0
Preprocessor directive indent: 0
- [5] 编译窗口乱码
# 方法一:
"文件" -> "设置" -> "编辑器" -> "文件编码" -> "全局编码"、"项目编码"、"属性文件的默认编码"全部设置为"UTF-8"
# 方法二:
"设置" -> "时间和语言" -> "语言和区域" -> "管理语言设置" -> "更改系统区域设置" -> 勾选"Beta 版:使用Unicode UTF-8提供语言支持(U)" -> "确定" -> "重启电脑"
3.clion配置WSL开发环境
3.1 WSL配置ssh-server
- (1) 下载配置文件:
>> wget https://raw.githubusercontent.com/JetBrains/clion-wsl/master/ubuntu_setup_env.sh
- (2) 修改配置文件:注意如果你用的是
~/.bashrc
,把脚本中.zshrc
都改成.bashrc
>> vim bash ubuntu_setup_env.sh
#!/bin/bash
set -e
SSHD_LISTEN_ADDRESS=0.0.0.0
SSHD_PORT=2222
SSHD_FILE=/etc/ssh/sshd_config
SUDOERS_FILE=/etc/sudoers
# 0. update package lists
sudo apt-get update
# 0.1. reinstall sshd (workaround for initial version of WSL)
sudo apt remove -y --purge openssh-server
sudo apt install -y openssh-server
# 0.2. install basic dependencies
sudo apt install -y cmake ninja-build gcc clang gdb valgrind build-essential
# 1.1. configure sshd
sudo cp $SSHD_FILE ${SSHD_FILE}.`date '+%Y-%m-%d_%H-%M-%S'`.back
sudo sed -i '/^Port/ d' $SSHD_FILE
sudo sed -i '/^ListenAddress/ d' $SSHD_FILE
sudo sed -i '/^UsePrivilegeSeparation/ d' $SSHD_FILE
sudo sed -i '/^PasswordAuthentication/ d' $SSHD_FILE
echo "# configured by CLion" | sudo tee -a $SSHD_FILE
echo "ListenAddress ${SSHD_LISTEN_ADDRESS}" | sudo tee -a $SSHD_FILE
echo "Port ${SSHD_PORT}" | sudo tee -a $SSHD_FILE
echo "UsePrivilegeSeparation no" | sudo tee -a $SSHD_FILE
echo "PasswordAuthentication yes" | sudo tee -a $SSHD_FILE
# 1.2. apply new settings
sudo service ssh --full-restart
# 2. autostart: run sshd
sed -i '/^sudo service ssh --full-restart/ d' ~/.zshrc
echo "%sudo ALL=(ALL) NOPASSWD: /usr/sbin/service ssh --full-restart" | sudo tee -a $SUDOERS_FILE
cat << 'EOF' >> ~/.zshrc
sshd_status=$(service ssh status)
if [[ $sshd_status = *"is not running"* ]]; then
sudo service ssh --full-restart
fi
EOF
# summary: SSHD config info
echo
echo "SSH server parameters ($SSHD_FILE):"
echo "ListenAddress ${SSHD_LISTEN_ADDRESS}"
echo "Port ${SSHD_PORT}"
echo "UsePrivilegeSeparation no"
echo "PasswordAuthentication yes"
- (2) 更新配置:
>> bash ubuntu_setup_env.sh
3.2 测试WSL能否通过ssh连接
>> ssh <username>@localhost -p2222
例如:
>> ssh mirror@localhost -p2222
The authenticity of host '[localhost]:2222 ([127.0.0.1]:2222)' can't be established.
ED25519 key fingerprint is SHA256:k/rR5fSXy7zB/BjTKUEZevce+y44IrNkE5cTJ0xuR9I.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[localhost]:2222' (ED25519) to the list of known hosts.
mirror@localhost's password:
➜ ~ ls
software workspace
3.3 配置clion
- (a) 添加工具链:"File" -> "Settings" -> "Build,Execution,Deployment" -> "Toolchains" -> "+" -> "WSL" -> "OK"
- (b) 配置文件夹映射:"File" -> "Settings" -> "Build,Execution,Deployment" -> "Deployment" -> "Connection" -> "SSH configuration" -> "..." -> "Host": localhost,"Port": 2222,"Authentication type": Password,"Password": WSL登录密码 -> "Test Connection" -> "OK"
- (c) 设置文件映射:"File" -> "Settings" -> "Build,Execution,Deployment" -> "Deployment" -> "Mappings" -> "Local path": 当前工程路径,"Deployment path": 映射到WSL里面的路径
- (d) 配置Converage:"File" -> "Settings" -> "Build,Execution,Deployment" -> "Coverage" -> "gcov": \wsl$\Ubuntu-20.04\usr\bin\gcov -> "OK"
4.使用vcpkg作为包管理器
"View" -> "Tool Windows" -> "Vcpkg" -> "+" -> "Directory"设置成你安装vcpkg的路径即可