User:Nmariusp/Clion: Difference between revisions
(→Run) |
(See also) |
||
Line 197: | Line 197: | ||
</pre> | </pre> | ||
Make sure that the value of the environment variables is correct. | Make sure that the value of the environment variables is correct. | ||
==See also== | |||
https://community.kde.org/User:Nmariusp/Qt_Creator |
Latest revision as of 03:12, 19 November 2024
JetBrains CLion for programming for KDE
JetBrains CLion (CLion) is a proprietary IDE for C++. For pricing details see https://www.jetbrains.com/clion/buy
A screen recording version is available https://www.youtube.com/watch?v=j2bCBlZLujA https://www.youtube.com/watch?v=G4CzVfSzv3s https://www.youtube.com/watch?v=_V5AqMj2fWc
See also https://community.kde.org/Get_Involved/development/IDE_configuration/CLion
Install CLion
Instal the app "JetBrains Toolbox" https://www.jetbrains.com/toolbox-app > "Download .tar.gz (Linux 64-bit x86)". A file such as https://download-cdn.jetbrains.com/toolbox/jetbrains-toolbox-2.1.3.18901.tar.gz will be downloaded. Download it to the directory ~/Downloads
.
mkdir -p ~/.opt/jetbrains-toolbox cd ~/Downloads tar -xzvf jetbrains-toolbox-2.1.3.18901.tar.gz -C ~/.opt/jetbrains-toolbox --strip-components=1
Execute ~/.opt/jetbrains-toolbox/jetbrains-toolbox
. E.g.:
~/.opt/jetbrains-toolbox/jetbrains-toolbox &
The "Welcome to Toolbox App" first run wizard is shown > Continue > Accept License Agreement > Dark > Get Started.
The main window of the app "JetBrains Toolbox" is shown. From the button with gear icon and tooltip "Toolbox App Menu" > "Quit Ctrl+Q".
In your start menu you will now have the application "JetBrains Toolbox", which is actually installed in ~/.local/share/JetBrains/Toolbox/bin/jetbrains-toolbox
.
From the start menu, open the application "JetBrains Toolbox". From the "Tools" tab > Available > "CLion A cross-platform C and C++ IDE" > "Install" button.
In your start menu you will now have the application "CLion A cross-platform C and C++ IDE", which is actually installed in ~/.local/share/JetBrains/Toolbox/apps/clion/bin/clion.sh
.
Alternative installation instructions
E.g. from the official webpage of CLion, select "Get Free 30-day Trial". A file such as https://download-cdn.jetbrains.com/cpp/CLion-2023.2.1.tar.gz will be downloaded. Download it to the directory ~/Downloads
.
mkdir -p ~/.opt/clion cd ~/Downloads tar -xzvf CLion-2023.2.1.tar.gz -C ~/.opt/clion --strip-components=1
Execute ~/.opt/clion/bin/clion.sh
. E.g.:
~/.opt/clion/bin/clion.sh &
First run
When CLion starts for the first time, the dialog "Import CLion Settings" is shown, select "Do not import settings", OK. Data Sharing dialog > "Don't Send".
The "Licenses" dialog is shown, select the radio button "Start trial", click on the "Start Trial" button, click on the "Continue" button.
The CLion application is started. Make sure that you have in the start menu the app "CLion A cross-platform C and C++ IDE". If you do not have it, you can create a desktop entry, from the CLion main menu > Tools > Create Desktop Entry. Now you can start CLion from the start menu (e.g. from the KDE Application Launcher or from krunner).
Open a KDE project in CLion
I configure kdesrc-build to use the CMake build configuration "Debug" in order to be able to use the debugger in the IDE.
cmake-options -DCMAKE_BUILD_TYPE=Debug ... num-cores 14
We'll use kcalc as an example KDE module and git repository. First, make sure it was built correctly using kdesrc-build
.
kdesrc-build kcalc
Build just the project but with verbose output this time:
kdesrc-build kcalc --no-src --no-include-dependencies --refresh-build --debug
Look at the output, write down the part similar to:
Running cmake targeting Kate - Ninja... cd /home/username/kde/build/kcalc run_logged_command(): Module kcalc, Command: cmake -B . -S /home/username/kde/src/kcalc -G Kate - Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON -DCMAKE_BUILD_TYPE=Debug -DQT_NO_CAST_FROM_ASCII=ON -DQT_NO_CAST_TO_ASCII=ON -DBUILD_WITH_QT6=ON -DCMAKE_CXX_FLAGS:STRING=-pipe -DCMAKE_INSTALL_PREFIX=/home/username/kde/usr -DCMAKE_PREFIX_PATH=/home/username/Qt/6.6.1/gcc_64 Setting environment variable QT_PLUGIN_PATH to /home/username/kde/usr/lib64/plugins:/home/username/kde/usr/lib/plugins Setting environment variable XDG_DATA_DIRS to /home/username/kde/usr/share:/home/username/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share Setting environment variable PATH to /home/username/kde/usr/bin:/home/username/Qt/6.6.1/gcc_64/bin:/home/username/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/username/.local/share/JetBrains/Toolbox/scripts Setting environment variable PKG_CONFIG_PATH to /home/username/kde/usr/lib/pkgconfig:/home/username/Qt/6.6.1/gcc_64/lib/pkgconfig Setting environment variable CMAKE_PREFIX_PATH to /home/username/Qt/6.6.1/gcc_64:/home/username/kde/usr Setting environment variable LD_LIBRARY_PATH to /home/username/kde/usr/lib:/home/username/Qt/6.6.1/gcc_64/lib Setting environment variable CMAKE_MODULE_PATH to /home/username/Qt/6.6.1/gcc_64/lib/cmake:/home/username/kde/usr/lib64/cmake:/home/username/kde/usr/lib/cmake # kdesrc-build running: 'cmake' '-B' '.' '-S' '/home/username/kde/src/kcalc' '-G' 'Kate - Ninja' '-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON' '-DCMAKE_BUILD_TYPE=Debug' '-DQT_NO_CAST_FROM_ASCII=ON' '-DQT_NO_CAST_TO_ASCII=ON' '-DBUILD_WITH_QT6=ON' '-DCMAKE_CXX_FLAGS:STRING=-pipe' '-DCMAKE_INSTALL_PREFIX=/home/username/kde/usr' '-DCMAKE_PREFIX_PATH=/home/username/Qt/6.6.1/gcc_64' # from directory: /home/username/kde/build/kcalc
In the "Welcome to CLion" wizard > "Open" > "/home/username/kde/src/kcalc/CMakeLists.txt" > OK. The dialog "Open Project CMakeLists.txt is a project file. Would you like to open the project?" is shown, select "Open as Project". Enable check box "Trust projects in ~/kde/src" > "Trust Project" button. In the "Open Project Wizard" dialog select "OK".
CMake configure
Look at the the part that you have written down previously, from the output of kdesrc-build kcalc --debug ...
.
In the CLion main menu > File > Settings > Build, Execution, Deployment > CMake > select the "Profile" named "Debug". "Build directory:" "/home/username/kde/build/kcalc". You can find the build directory above in the part "cd /home/username/kde/build/kcalc".
CMake options:
-G "Kate - Ninja" -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON -DCMAKE_BUILD_TYPE=Debug -DQT_NO_CAST_FROM_ASCII=ON -DQT_NO_CAST_TO_ASCII=ON -DBUILD_WITH_QT6=ON -DCMAKE_CXX_FLAGS:STRING=-pipe -DCMAKE_INSTALL_PREFIX=/home/username/kde/usr -DCMAKE_PREFIX_PATH=/home/username/Qt/6.6.1/gcc_64
You can find the value of "CMake options:" above in the part ", Command: cmake -B ". Ignore the command line parameters "-B" and "-S" and paste the rest of the cmake command line into "CMake options:".
Convert using a text editor and text replace:
Setting environment variable QT_PLUGIN_PATH to /home/username/kde/usr/lib64/plugins:/home/username/kde/usr/lib/plugins Setting environment variable XDG_DATA_DIRS to /home/username/kde/usr/share:/home/username/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share Setting environment variable PATH to /home/username/kde/usr/bin:/home/username/Qt/6.6.1/gcc_64/bin:/home/username/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/username/.local/share/JetBrains/Toolbox/scripts Setting environment variable PKG_CONFIG_PATH to /home/username/kde/usr/lib/pkgconfig:/home/username/Qt/6.6.1/gcc_64/lib/pkgconfig Setting environment variable CMAKE_PREFIX_PATH to /home/username/Qt/6.6.1/gcc_64:/home/username/kde/usr Setting environment variable LD_LIBRARY_PATH to /home/username/kde/usr/lib:/home/username/Qt/6.6.1/gcc_64/lib Setting environment variable CMAKE_MODULE_PATH to /home/username/Qt/6.6.1/gcc_64/lib/cmake:/home/username/kde/usr/lib64/cmake:/home/username/kde/usr/lib/cmake
by replacing " Setting environment variable " with "", and by replacing " to " with "=" to:
QT_PLUGIN_PATH=/home/username/kde/usr/lib64/plugins:/home/username/kde/usr/lib/plugins XDG_DATA_DIRS=/home/username/kde/usr/share:/home/username/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share PATH=/home/username/kde/usr/bin:/home/username/Qt/6.6.1/gcc_64/bin:/home/username/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/username/.local/share/JetBrains/Toolbox/scripts PKG_CONFIG_PATH=/home/username/kde/usr/lib/pkgconfig:/home/username/Qt/6.6.1/gcc_64/lib/pkgconfig CMAKE_PREFIX_PATH=/home/username/Qt/6.6.1/gcc_64:/home/username/kde/usr LD_LIBRARY_PATH=/home/username/kde/usr/lib:/home/username/Qt/6.6.1/gcc_64/lib CMAKE_MODULE_PATH=/home/username/Qt/6.6.1/gcc_64/lib/cmake:/home/username/kde/usr/lib64/cmake:/home/username/kde/usr/lib/cmake
Save the text block above to file ~/kde/clion-cmake.txt
. The same text block will be needed when opening in CLion other KDE project.
Copy to clipboard the content of the file ~/kde/clion-cmake.txt
. In "Environment:" on the button at the right side of the edit box with tooltip "Edit environment variables (Shift+Enter)". Click on the button with the tooltip "Paste". Press "OK" button.
rm -rf ~/kde/build/kcalc
In the bottom left select the button with the tooltip "CMake", this will open the CMake tool window. Press the button with tooltip "Clear All", press the "Reload CMake Project" button. Make sure that the output is correct. From the CLion main menu > Build > Rebuild "kcalc".
Run
cat ~/kde/build/kcalc/prefix.sh
says:
export PATH=/home/username/kde/usr/bin:$PATH export XDG_DATA_DIRS=/home/username/kde/usr/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share} export XDG_CONFIG_DIRS=/home/username/kde/usr/etc/xdg:${XDG_CONFIG_DIRS:-/etc/xdg} export QT_PLUGIN_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/plugins:$QT_PLUGIN_PATH export QML2_IMPORT_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/qml:$QML2_IMPORT_PATH export QT_QUICK_CONTROLS_STYLE_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/qml/QtQuick/Controls.2/:$QT_QUICK_CONTROLS_STYLE_PATH export MANPATH=/home/username/kde/usr/share/man:${MANPATH:-/usr/local/share/man:/usr/share/man} export SASL_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/sasl2:${SASL_PATH:-/usr/lib/x86_64-linux-gnu/sasl2}
Run:
source ~/kde/build/kcalc/prefix.sh echo PATH=$PATH echo XDG_DATA_DIRS=$XDG_DATA_DIRS echo XDG_CONFIG_DIRS=$XDG_CONFIG_DIRS echo QT_PLUGIN_PATH=$QT_PLUGIN_PATH echo QML2_IMPORT_PATH=$QML2_IMPORT_PATH echo QT_QUICK_CONTROLS_STYLE_PATH=$QT_QUICK_CONTROLS_STYLE_PATH echo MANPATH=$MANPATH echo SASL_PATH=$SASL_PATH
says:
PATH=/home/username/kde/usr/bin:/home/username/.local/bin:/home/username/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/username/.local/share/JetBrains/Toolbox/scripts XDG_DATA_DIRS=/home/username/kde/usr/share:/usr/local/share:/usr/share:/var/lib/snapd/desktop XDG_CONFIG_DIRS=/home/username/kde/usr/etc/xdg:/home/username/.config/kdedefaults:/etc/xdg QT_PLUGIN_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/plugins: QML2_IMPORT_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/qml: QT_QUICK_CONTROLS_STYLE_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/qml/QtQuick/Controls.2/: MANPATH=/home/username/kde/usr/share/man:/usr/local/share/man:/usr/share/man SASL_PATH=/home/username/kde/usr/lib/x86_64-linux-gnu/sasl2:/usr/lib/x86_64-linux-gnu/sasl2
Save the text block above to file ~/kde/expanded-prefix-sh.txt
. The same text block will be needed when opening in the IDE JetBrains CLion other KDE projects. The content of this file is also needed when running or debugging a KDE project in other IDEs e.g. Qt Creator.
Copy to clipboard the content of the file ~/kde/expanded-prefix-sh.txt
. From the CLion main menu > Run > Edit Configurations... > kcalc. In "Environment variables:" click on the button at the right side of the edit box with tooltip "Edit environment variables (Shift+Enter)". Click on the button with the tooltip "Paste" to paste from the clipboard. Press "OK" button twice.
Now you can run kcalc correctly, from the CLion main menu > Run > Run 'kcalc' Shift + F10.
Now you can debug kcalc correctly, from the CLion main menu > Run > Debug 'kcalc' Shift + F9.
As a test that CLion runs kcalc correctly, in CLion, start debugging the process kcalc and pause the debugger e.g. by pressing the pause program kcalc button. In the bottom left button "Debug Alt+5" > tab "GDB" > run the command info proc
. It says:
(gdb) info proc process 89954 cmdline = '/home/username/kde/build/kcalc/bin/kcalc' cwd = '/home/username/kde/build/kcalc/bin' exe = '/home/username/kde/build/kcalc/bin/kcalc'
In a terminal:
xargs -0 printf %s\\n < /proc/89954/environ
Make sure that the value of the environment variables is correct.