Configuration MinGW

Download and install MinGW

Download MinGW here must pay attention to is to download the compressed package, do not download the offline installation of the version, otherwise you will be installed to monkey years, and the installation is difficult. Open the download address: [MinGW] (sourceforge.net/projects/mi… Targetting Win64/Personal Builds/mingw-builds/) go to the download page

Note: don’t touch the green button to download!! Scroll down to the screen below to download the zip package.

And, of course, if abandon this speed too slow, you can use the network location to download links: pan.baidu.com/s/1zd5hgyvX… Password: obb8 Download must be decompressed, then start to configure CLion.

Configuration CLion

Open CLion, file-settings-Build-ToolChains in the upper left corner, and click the + sign

That is, configure your own toolchain (MinGW in Win). The following connection to a Remote Host is also a tool chain.

Go to toolChains to add configuration, Environment select MinGW, and then fill in the path of the newly extracted MinGW64:

C:\Users\71022\Documents\mingw64
Copy the code

Then CLion will automatically fill in everything you need to fill in, click OK, and wait for the bug to turn green.

Of course, there will be a failure to detect the success of the situation, at this time you need to fill in manually. CMake usually selects it automatically. Make enter path:

C:\Users\71022\Documents\mingw64\bin\mingw32-make.exe
Copy the code

C Compiler:

C:\Users\71022\Documents\mingw64\bin\gcc.exe
Copy the code

C++ Compiler:

C:\Users\71022\Documents\mingw64\bin\g++.exe
Copy the code

The Debugger usually fills in the Debugger itself. If not, you can manually fill in the Debugger:

C:\Users\71022\Documents\mingw64\bin\gdb.exe
Copy the code

Compilation executes a single file

Clion cannot compile a file separately and execute it as cmake. CMakeLists need to be modified to execute the file separately by setting external Tools

Configure External Tools

Configure shortcut Keys

test

Use CLion to connect to a remote development environment

Due to the need to write C language program under Linux platform, but directly based on terminal GDB debugging, the development efficiency is very low.

Under Windows platform, it is very convenient to use CLion to remotely call GDB for Linux environment C language development.

Configure remote server open connection

This is an Ubuntu VIRTUAL machine, and you want to open an SSH connection

1. Install openssh server. –

SSH includes SSH client Openssh-client and SSH server Openssh-server. Through Openssh-Client, you can remotely log in to other hosts. Openssh-server is required to open the LOCAL SSH service. Openssh-client is installed in Ubuntu by default, but Openssh-Server is not installed. Therefore, we cannot use SSH to access Ubuntu inside the VM on the host.

Install openssh-server: sudo apt-get install -y openssh-server

2. Modify the configuration file

By default, the SSHD service does not support remote connection by the root user. Therefore, you need to modify the /etc/ssh/sshd_config file of the SSHD to change PermitRootLogin from the default no-password to yes. Then run sudo service SSH restart or sudo /etc/init.d/ SSH restart to restart the SSHD service.

3. Restart the VM

Can use ps – ef | grep SSHD to check whether the SSHD service is started.

SSH Remote connection to the server

Settings -> Tools -> SSH Configurations -> Configure the SSH connection

In this case, you can use SSH to connect to the server

SFTP accesses a remote directory

File –> Settings –> Deployment, configure the remote Connection, and click “Mappings” to configure the mapping relationship

Search for Remote Host on the CLion home page and click to bring up the server files directory

Connecting to a Remote Host

File –> Setting –> Build, Execution, Deployment –> ToolChains– >Remote Host –> Credentials to select the Ubuntu Host to connect to

Deploy/synchronize file directories

Upload the entire project to the corresponding folder on the Ubuntu server

Remote Server Configuration

Note that the server needs to have GCC, g++, GDB, cmake installed as high as possible

CMake installation

Apt install cmake This installation mode cmake version is too early, may not meet the requirements, use wget official website download: link.zhihu.com/?target=htt…

Decompress: tar -zxv -f cmake-3.19.3.tar.gz

Sudo apt install libssl-dev openssl

Go to the directory and run./bootstrap

If there is no error, execute sudo make -j8

After compiling the source code, run sudo make install

Enter: cmake –version To view the version

Ensure that the Cmake versions in The Win and Linux operating systems are consistent

Configure the Clion Remote Host make path

In Ubuntu, /usr/bin for Linux keeps a shortcut similar to Windows 10, and CLion and many others automatically look for a shortcut in /usr/bin; If you have the package installed but it is not in /usr/bin, CLion etc will not be found.

In this case, you need to use Linux’s ln command to create shortcut to the installation package installation location:

Ln -sf/your CMake installation location /bin/* /usr/bin/

Configure CLion CMake to use a remote server

Build,… ->CMake, select remote host in toolchain

Set up remote GDB debugging

Edit the configuration in the upper right corner of the main screen

Adding remote Debug

Note Enter TCP and the port number: Target remote args: TCP :192.168.1.110:1234

Go to the development directory and enter the command

cd /usr/local/sun_test
sudo mkdir build
cd build
sudo cmake .. -DCMAKE_BUILD_TYPE=Debug
sudo make
Copy the code

Next, run the following command on your terminal (OS is the executable you generated) :

gdbserver :1234 /usr/local/sun_test/build/OS
Copy the code

Start debugging, run gdbServer to listen on port 1234. Can be directly in windows10 platform for breaking points, debugging, will be displayed in ubuntu

Other problems

Add add_executable to CMakeLists

Use the plugin C+ Single File Execution

Output the code

Change to GBK or UTF-8, but need to change back and forth between running and debug

Remote code completion

Make sure CMake in the Remote link ToolChains selects the Remote Host.

After clicking on Help | Find Action, input Registry, after check the clion. Remote. Tar. Dereference

Clion remote auto-completion caches relevant header files under remote Liunx to the local, and this cache is first packaged with tar, and then downloaded to the local. However, some header files on Linux are actually soft links, and tar packages them according to soft links, which cannot be resolved after downloaded to the local and decompressed. Dereference is checked clion. Remote. Tar. Let the tar command Enable dereference (-h) and ‘- hard – dereference tar the arguments can parse so soft links to the corresponding files, Downloading to local is a file, not a soft link.

Tool -> Resync with remote hosts. If this does not work, delete the local cache and Resync. Local cache can be found in C:\Users\ username \AppData\Local\JetBrains\ clion20211.1. remote Permission Denied)