我已經在博客里面發布了好幾篇 CLion 使用筆記了,沒追究這是第幾篇,姑且算作第三篇。
我的 CLion 是搭配了 MSYS2 和 Conan 使用的。MSYS2 提供 C++ toolchain。Conan 作為 C++ 包管理工具,用它可以方便地安裝 Boost 等 C++ 庫。
MSYS2 真是個好東西。很多包都更新得很快。我又有更新強迫症。每天好幾遍 pacman -Syuu
。剛才把 GCC 更新到了 9.1。GCC 9.1 是 5 月 3 號發布的。
每次更新 GCC 之后,需要在 CLion 中的一些地方修改 GCC 的版本,這些修改是關於 CMake 和 Conan 的。
關於 CMake 的修改
- 刪除 cmake-build-debug/CMakeCache.txt (也可能是 cmake-build-release/CMakeCache.txt 或其他路徑)
- File > Reload CMake Project
UPDATE
cmake-build-debug/conaninfo.txt 中也有編譯器版本信息 compiler.version
,需要確認其值是否正確。
關於 Conan 的修改
這一步也許不是必須的,不過我一般都會做。就是用最新的 GCC 把通過 Conan 安裝的包重新 build(編譯)一下。
方法是
點擊 CLion 窗口底部的 Terminal 標簽。
在 Terminal 中切換到項目的根目錄,然后執行
conan install . --install-folder=cmake-build-debug --build-missing '與編譯器版本和編譯器路徑相關的參數'
根據官方文檔,可以把上述「與編譯器版本和編譯器路徑相關的參數」寫到一個配置文件里,這種配置文件稱為 profile。注意,profile 文件不需要擴展名。
我把我用的 profile 文件命名為 gcc,其內容是
# I define this variable to store the root direcory of GCC
GCC_BIN=D:\msys64\mingw64\bin
[settings]
os=Windows
arch=x86_64
compiler=gcc
# set compiler.version to the proper value
compiler.version=9.1
compiler.libcxx=libstdc++11
build_type=Debug
[options]
[build_requires]
[env]
CC=$GCC_BIN\gcc
CXX=$GCC_BIN\g++
注意,在 profile 中,注釋要單獨寫在一行,不能寫在某個配置行的末尾。
通過 -pr 選項引入 profile,格式是 -pr=path/to/prile
。