foreword
CLion is a C++ integrated development environment (IDE) developed by JetBrains, which has many powerful functions, such as code completion, debugger, version control and so on. CLion itself is paid software, but if you are a student, you can apply for free use .
Test installation environment: Ubuntu18, Ubuntu22
1. Clion installation
(1) Official download and installation package
Official download and installation package
(2) Unzip the installation package
gzip -d CLion-2023.1.1.tar.gz
tar -xvf CLion-2023.1.1.tar
(3) Replace the jbr folder
When jetbrains family bucket is used in Ubuntu, there will be a problem that the input method does not follow. You need to replace the jbr folder in the source file to solve it
First download the jbr file recompiled by others on github: (If the Clion version is newer, the downloaded jbr version should also be newer. I use the Clion2023 version, and the downloaded jbr version is release 17.0.6 )
After downloading, unzip and rename to jbr
:
Then replace to the jbr folder in the Clion installation package:
(4) Copy the installation package \opt
into
sudo cp -rf CLion-2023.1.1 /opt
(5) Execute the installer
cd /opt/CLion-2023.1.1/bin
sh clion.sh
(6) Create a desktop shortcut key
(if the initial installation is complete, it should be an English interface, the picture below shows that I installed the Chinese plug-in)
(7) Download the Chinese version of the plug-in
Download the Chinese package plug-in in the plugs option in the settings of clion:
2.Clion configuration project
(1) Compiler configuration
(2) cmake configuration
(3) How does clion run the project
clion compiles and runs projects through cmake, and cmake compiles and runs projects can be divided into three steps:
One is cmake <source tree>
, for example cmake ..
, used to generate project files project files;
The second is that cmake --build .
the function of build is to adaptively build projects (or compile and link projects) based on the compiler of the current system. When you know that the compiler of your system is Unix Makefiles, you can also use it directly to build the project make
;
The third is to run the compiled executable file, such as ./main
;
Returning to clion, the first two steps are actually configuring the path of the compiler and the command line parameters of cmake. After configuration, running a project is actually divided into three steps like cmake:
First cmake ..
, when clion opens the project, it will be automatically generated cmake ..
. The default is to generate it in cmake-build-debug
the folder. Of course, you can also manually right-click the project and select it , but you need it after reload cmake project
you modify the file ;CMakeLists.txt
reload cmake project
The second is cmake --build .
that it corresponds to the function of the build button in clion. If an error is reported: Error: could not load cache
, then you have not completed step 1 reload cmake project
;
The third is ./main
, the run button in clion, in fact, the run button will complete step 2 and step 3 at the same time, that is, run will build first, and then run the executable file;