Use QT Creator as Linux IDE instead of vim: Implement remote deployment and debugging of two Linux computers (one computer has a desktop system, one computer has no desktop system) __linux

Source: Internet
Author: User
Tags server port

Respect the author, support original, if need reprint, please attach original address: http://blog.csdn.net/libaineu2004/article/details/62423830

Preface

Considering that programmers do not have desktop Linux in the environment to write C/T + + programs, if the use of raw vim editing and one-step breakpoint debugging more trouble, not conducive to novice use, so I tried to use QT to achieve two Linux remote deployment and debugging. That is, the programmer is debugging the computer using QT to write code, and then the target program deployed on the official computer. This article is to help you get rid of vim, once and for all, to solve the pain point. Please do not mistakenly think that Qt creator can only be used to do desktop software, in fact, it can also create a new pure C + + non-desktop engineering, can Qmake can also be cmake compiled. Prepare two computers for verification, one has a Linux desktop system, using QT Creator for editing the source debugging environment, the other only terminal, no Linux desktop system, for the server formal environment. The Qt Linux version is installed on the debug machine. This paper takes Qt-opensource-linux-x64-5.7.1.run as an example. qt Download URL is: http://download.qt.io/official_releases/qt/

Two computers (note: This article takes the debugger and the target machine as the distinguishing description) uses the network cable connection, the related situation as shown:


Body

1. Ensure that GCC and GDB are installed on the Linux debugging machine.

will not be installed please refer to the following article:

Http://www.linuxidc.com/Linux/2015-01/112057.htm

http://blog.csdn.net/yang1982_0907/article/details/38461127

Precautions:

You must have GCC installed to compile gdb. CentOS 7 the command to automatically install GCC is: yum-y install gcc make glibc

After installing GCC, execute Terminal command gcc-v can view the installed version information. CentOS 7 The default GCC version is V4.8.5.

CentOS 7 The command to view IP addresses is: IP addr

GDB Source URL is downloaded: http://ftp.gnu.org/gnu/gdb/compiled gdb source code, you must install the Texinfo document System. Otherwise, compile GDB source code will error Configure:error:no termcap library found.

Take CentOS 7 As an example, the installation command is yum install Ncurses-devel

Take the source gdb-7.6.1.tar.gz as an example, execute the command tar xzvf gdb-7.6.1.tar.gz after decompression, in the first level of directory/GDB-7.6.1/, execute the following command to compile:

CD gdb-7.6.1

./configure

Make

Make install

The gdb file is then generated in the path/usr/local/bin/, and terminal commands are executed gdb-v can view the installed version information.


2. Install GDB and gdbserver in Linux target machine

The GDB version of the debugger and target must be consistent. The compilation method is consistent.

Take the source gdb-7.6.1.tar.gz as an example, execute the command tar xzvf gdb-7.6.1.tar.gz after decompression, in the first level of directory/GDB-7.6.1/, execute the following command to compile:

CD gdb-7.6.1

./configure

Make

Make install

The GDB and gdbserver files are then generated at the same time in the path/usr/local/bin/.

The gdbserver of the target machine is critical and cannot be debugged with one step without it. Remember. The correct way to verify that GDB and Gdbserver are installed is:

Execute Terminal command

Gdb-v

Gdbserver--version

If the version number is displayed correctly, the installation is successful.

If you want to compile Gdbserver separately ( Note: We do not need to perform this step here, as the above method already contains ), you need to go into the/gdb-7.6.1/gdb/gdbserver and compile the following command:

./configure

Make

Make install

The Gdbserver file is then generated in the path/usr/local/bin/, and the terminal command is executed Gdbserver--version can view the installed version information.


3, in the Linux debugging machine set the target machine information

Qt Creator Menu->tools->options->devices->add

New Linux Universal devices:

Fill in the target IP address (LAN and public IP are supported), Root and password:

The performance after SSH connectivity:


Configure remote debugging and compilation environments, custom named "Firecattest":

4, a new NON-QT project to do test verification, NON-QT project refers to non-Qt library programming, that is, the original eco-C + + programming Linux.

Kit selection to select "Firecattest":


If you are using the Qmake compilation method, you need to add the following sentences to the project. Pro file:

#远程部署, define the path of the compiled file to the remote Linux target, and the path can be customized

Target.path=/home/firecat/test

Installs + target

Compile, run, done. The execution file Mywin32 is generated under the/home/firecat/test path of the target machine.

If you take the cmake approach, the end of the article tells the method.

5, how to remote single step debugging. The prerequisite is to first turn off the firewall of the Linux target computer.

CentOS 7 commands for operating the firewall are:

Firewall-cmd--state #查看防火墙是否启用

Systemctl Stop Firewalld #关闭防火墙

What to do after shutting down the firewall. How to implement one step breakpoint debugging. Remember in step 2 of the article, to install GDB and gdbserver on the target machine. And then

Method One (recommended): Simple and clear, in the Debugging machine project source under good breakpoints, directly press F5, the default way to step through debugging.

Method two (not recommended): much more complex.

(1) running the Gdbserver command at the Linux target terminal:

/usr/local/bin/gdbserver 172.16.6.166:9900/home/firecat/test/mywin32

Where 172.16.6.166 is the IP address of the debugger, 9900 is a random TCP port number, MYWIN32 is a programming-generated target execution file.

(2) on the Linux debugging machine, set the parameters of QT single-step debugging:

Qt Creator Menu->debug->start debugging->attach to Running Debug Server

Where server port refers to the TCP port, server address refers to the target machine's IP addresses;

Local executable refers to the build file of the project locally (debug machine).

Parameter set up, click OK button, start debugging.


6, if you do not want to use Qmake, but CMake compile and debug the program, how to achieve. Visit the Sister chapter, "using QT Creator as the Linux IDE, implementing CMake Compilation and Single-step debugging," with the URL:

http://blog.csdn.net/libaineu2004/article/details/78448392

Note: CMake the target path of the remote build, the default is/root/xxx. You can manually modify the CMakeLists.txt file to change the output path, SET (executable_output_path "* * *"). So the path of both the developer and the target machine will have a build result. My test result is, looks like the path inside has the home directory, the target machine is not good. For example, set (Executable_output_path "/home/12/"), the resulting file developer is in, but the target is not, but the folder is generated/12 in the root directory. Another example is the "/home/firecat/test" target machine is not in, but the root directory to generate the "test" folder.

Cmake_minimum_required (VERSION 2.8)

Project (Untitled)
add_executable (${project_name} "main.cpp" "Test.cpp" ")
# #SET (executable_output_path"/home/firecat/test/")
SET (executable_output_path"/hellotest/12/34 ")



Respect the author, support original, if need reprint, please attach original address: http://blog.csdn.net/libaineu2004/article/details/62423830

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.