c++_编辑器CLion

c++_编辑器CLion


前篇

比 vscode 轻量, 使用 cmake.


破解

参考: others-jetbrains编辑器.md


编辑器使用

编译配置

file -> settings -> build,exception,deployment


sh.exe 不能再 PATH 中

sh.exe 在 PATH 中, 新建 library 工程会报错:

1
2
3
4
5
CMake Error at D:/CLion 2019.3.3/bin/cmake/win/share/cmake-3.15/Modules/CMakeMinGWFindMake.cmake:12 (message):
sh.exe was found in your PATH, here:
D:/Git/bin/sh.exe
For MinGW make to work correctly sh.exe must NOT be in your path.
Run cmake from a shell that does not have sh.exe in your PATH.

解决办法: 重命名其他接, 如: sh.exe 重命名为为 sh_bak.exe

查看是否成功, file -> settings -> build,exception,deployment -> toolchains, c++ compiler 没有报错即可.


取消方法形参显示

这个和通用的 jetbrains 编辑器不同, 藏在了这里

file -> settings -> editor -> Inlay Hints -> c/c++, 取消勾选 show parameter hints


编译器 mingW 设置

  • file -> settings -> build, excution… -> toolchains


重置 cmake 缓存

  1. 先将 cmake-build-debug 里面的文件全删了
  2. tools -> cmake -> reset cache and reload project. 过几秒就可以重新生成, 就可以 build and run.

重新加载 CMakeLists.txt

tools -> cmake -> reload cmake project

或者

cmake 窗口: view -> tool windows -> cmake

相当于 取消自动 reload 后, 弹出的 reload changes


debug/release 构建

clion 默认构建的是 debug 版本

添加 release 版本, file -> setting -> build, execution .. -> cmake, 添加编译版本, 构建时会同时构建这几个版本.


技巧

自动生成 方法/变量

先敲出不存在的 方法/变量, 然后 alt + enter 选择 create new …


踩坑

新建 library 报错

报错: sh.exe was found in your PATH

解决参考: [sh.exe 不能再 PATH 中](#sh.exe 不能再 PATH 中)


Error: could not load cache

是因为删除了 cmake-build-debug 文件夹 或 里面自动生成的文件, 重新生成一下即可. 参考: [重置 cmake 缓存](#重置 cmake 缓存)


新加文件不能编译生效

  1. 先确保在 CMakeLists.txt 加进去了
  2. [重新加载 CMakeLists.txt](#重新加载 CMakeLists.txt)

不生效万能大法

可以尝试一下两个步骤:

  1. [重置 cmake 缓存](#重置 cmake 缓存)
  2. [重新加载 CMakeLists.txt](#重新加载 CMakeLists.txt)