Clion connection wsl
The first step is to install WSL
①Enable Windows Subsystem for Linux
Open PowerShell as administrator and run the following command:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
②Enable virtual machine function
Open PowerShell as administrator and run the following command:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
③Download the appropriate version of Ubuntu from Microsoft Store
Click the get button to download
After the download is complete, open
The second step is to install cmake and the required configuration files
②Write a script file in any directory of wsl
sudo touch a.sh --------------------------Create script file
sudo vim a.sh ---------------------Open and write script file
After entering the script file, click the insert key on the keyboard to enter the writing mode, copy the script content into it, press the esc key to enter the editing mode, enter two ZZ to save and exit.
The script file code is as follows:
if [ -e "/dev/vsock" ]; then # in case of WSL2
SSHD_FILE=/etc/ssh/sshd_config
0.1. reinstall sshd (workaround for initial version of WSL)
sudo apt remove -y --purge openssh-server
sudo apt install -y openssh-server
0.2. install basic dependencies
sudo apt install -y cmake gcc clang gdb valgrind build-essential
sudo cp $SSHD_FILE ${SSHD_FILE}.date '+%Y-%m-%d_%H-%M-%S'.back
sudo sed -i '/^Port/ d' $SSHD_FILE
sudo sed -i '/^ListenAddress/ d' $SSHD_FILE
sudo sed -i '/^UsePrivilegeSeparation/ d' $SSHD_FILE
sudo sed -i '/^PasswordAuthentication/ d' $SSHD_FILE
echo "# configured by CLion" | sudo tee -a $SSHD_FILE
echo "ListenAddress ${SSHD_LISTEN_ADDRESS}"| sudo tee -a $SSHD_FILE
echo "Port ${SSHD_PORT}" | sudo tee -a $SSHD_FILE
echo "UsePrivilegeSeparation no" | sudo tee -a $SSHD_FILE
echo "PasswordAuthentication yes" | sudo tee -a $SSHD_FILE
sudo service ssh --full-restart
sed -i '/^sudo service ssh --full-restart/ d' ~/.bashrc
echo "%sudo ALL=(ALL) NOPASSWD: /usr/sbin/service ssh --full-restart" | sudo tee -a $SUDOERS_FILE
sshd_status=$(service ssh status)
if [[ $sshd_status = "is not running" ]]; then
sudo service ssh --full-restart
echo "SSH server parameters ($SSHD_FILE):"
echo "ListenAddress ${SSHD_LISTEN_ADDRESS}"
echo "UsePrivilegeSeparation no"
echo "PasswordAuthentication yes"
Run the script through the following command
The third step is to download clion
There are many tutorials online, you can search by yourself
https://www.cnblogs.com/citrus/p/13565519.html
The fourth step is to establish the clion wsl tool chain
①Open clion and open the following page through File->Settings->Build, Execution, Deployment->Toolchain
②Click the + OK button to add wsl
③The content in wsl will be automatically filled in
④Set up ssh
Find the following page through the following directory File->Settings->Tools->ssh configuration
The username and password are respectively the username and password you set in wsl.
The port number is port 2222 set in the script
——————————————————————————————————————————————————————
Since then, the clion and wsl connection configuration has been successful! ! !
——————————————————————————————————————————————————————
Configure clion to connect to the qt library and cross editor
The first step is to unzip the qt library and cross editor
①In the wsl command window, unzip the qt library and cross editor
Use the cd command to enter the file containing the qt library and cross-editor compressed packages.
Use the following command to decompress
tar -xvf gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf.tar
tar -xvf qt-5.12.3.tar
I have completed the decompression here. The first two files are the decompressed files.
The second step is to configure the path
①Open toolchain.cmake, and modify the path location in red to the location of the qt library and cross editor in your own file directory
The third step is to modify the toolchain.cmake path in clion.
①Open the following page through File->Settings->Build, Execution, Deployment->CMake
Click the + button to add Release-WSL. The build type is: Release toolchain WSL.
CMake选项:-DCMAKE_TOOLCHAIN_FILE=/mnt/d/Co2/package/toolchain.cmake
That is: -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake file directory
Click OK to complete the settings
———————————————————————————————————————————————————————
Since then the qt library and cross editor have been imported into clion! ! ! !
———————————————————————————————————————————————————————
Run the project
The first step is to put the project source code files in the English directory
The second step is to import the project into Clion and open it.
The third step is to find the main.cpp file and run it
Error occurred
Mistake 1: An error occurred when the project was built to 70%
Reason: WSL Ubuntu version is wrong
Solution: Build successfully after upgrading Ubuntu18.0 to Ubuntu20.04 version
Mistake 2: An error occurs after building to 100%
cannot execute binary file: Exec format error
The reason is that the GCC in the compilation chain is a 32-bit version, which wsl itself does not support.
Solution:
Install the qemu-user-static package, add the i386 binary file format, enable the i386 architecture, update the package list, and install some i386 packages
The wsl command is as follows:
①Install qemu and binfmt
sudo apt update
sudo apt install qemu-user-static
sudo update-binfmts --install i386 /usr/bin/qemu-i386-static --magic '\x7fELF\x01\x01\x01\x03\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x03\x00\x01\x00\x00\x00' --mask '\xff\xff\xff\xff\xff\xff\xff\xfc\xff\xff\xff\xff\xff\xff\xff\xff\xf8\xff\xff\xff\xff\xff\xff\xff'
These commands will activate i386 support by executing qemu-i386-static and place the configuration file into /var/lib/binfmts/ for future reactivation.
②This feature needs to be reactivated every time WSL is restarted and i386 support is required
sudo service binfmt-support start
③Enable i386 architecture and software packages
sudo dpkg --add-architecture i386
sudo apt update
sudo apt install gcc:i386
Mistake Three: Missing Files
Download arm-linux-gnueabihf and arm-linux-gnueabi and find the missing files in the lib file.
Copy to the lib file in the wsl home directory through the cp command
For example: the libpthread.so.0 file is missing for the first time
then exists in usr/arm-linux-gnueabihf/lib
Then pass the command in this directory
cp libpthread.so.0 /lib completes copying
Finally, after multiple copies, it finally ran successfully!