跳转至

CLion

簡介

CLion 是一款由 JetBrains 公司開發的功能豐富且強大的跨平台 C/C++ 集成開發環境(IDE)。

Clion

官方教程

在官方網站中給出了 學習 Clion 的教程。

安裝

參見 Download CLion

配置

工具鏈安裝

CLion 默認不帶編譯器,構建工具和調試工具,需要手動進行安裝。

Windows

參見 Tutorial: Configure CLion on Windows | CLion Documentation

值得一提的是 CLion 的 Windows 版本中自帶了 MinGW,所以可以不用額外安裝 MinGW 工具鏈。

Linux

Debian/Ubuntu 及其衍生發行版
1
2
3
sudo apt install make cmake # build tools
sudo apt install gcc g++ gdb # compiler and debugger
sudo apt install clang clang++ llvm lldb # you can also choose to use clang toolchain
Arch Linux 及其衍生發行版
1
2
3
sudo pacman -S make cmake # build tools
sudo pacman -S gcc g++ gdb # compiler and debugger
sudo pacman -S clang clang++ llvm lldb # you can also choose to use clang toolchain
Fedora/RHEL/CentOS/Rocky Linux
1
2
3
sudo dnf install make cmake # build tools
sudo dnf install gcc g++ gdb # compiler and debugger
sudo dnf install clang clang++ llvm lldb # you can also choose to use clang toolchain

MacOS

參見 Tutorial: Configure CLion on macOS | CLion Documentation

工具鏈設置

手動設置工具鏈

新安裝的 CLion 會自動檢測系統中的 C/C++ 開發工具鏈,如果已安裝的工具鏈無法自動檢測到,可在 Settings 中找到 Build, Execution, Deployment>Toolchains 進行手動配置。

Config Toolchains

CMake

設置

CLion 默認使用 CMake 作為構建工具,關於 CMake 的設置可以在 Build, Execution, Deployment>Toolchains>CMake 中修改。

CMake Settings

編譯選項

CMake 默認使用項目根目錄下的 CMakeList.txt 作為構建項目的配置文件,可以使用 add_compile_options 命令來增加編譯選項,例如:

1
add_compile_options(-std=c++17 -DDEBUG)

其他 CMake 的功能請參考 CMake 官方文檔

免費獲取 CLion IDE 許可證

CLion 為付費產品,但是可以通過教育郵箱或開源項目申請特殊許可證。申請之後不僅可以免費使用正版 CLion IDE, 還可以免費使用 JetBrains 公司開發的其他付費產品。

使用教育郵箱獲取

進入官網的 Free Educational Licenses 頁面, 點擊 Apply 按鈕,填寫相關信息即可申請。

Educational Licenses

注意:在註冊時於郵箱選項請填如 @edu.cn 後綴的教育郵箱,特殊許可證需要郵箱驗證後方可拿到。

你可以到所在高校的教務中心官網去申請教育郵箱,如果申請不到需要使用 學信網 進行認證(僅中國大陸)。

使用開源項目獲取

如果您是某個開源項目的核心開發者或維護者之一,您可以嘗試申請開源開發許可證 (Open Source Development License). 申請流程與教育許可證類似,但需要填寫開源項目的倉庫地址。

Open Source Development License