Use Qt Creator as Linux IDE to realize CMake compilation and single-step debugging ORBSLAM2 program

Respect the author and support originality. If you need to reprint, please attach the original address:

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

Part 1: Using Qt Creator as a Linux IDE to implement CMake compilation and single-step debugging

1. Preliminary preparation

1. Install Linux system, such as CentOS 7, with desktop, GNOME installation

2. Install qt-opensource-linux-x64-5.9.1.run

3. Install CMake, refer to the tutorial: Install cmake 2.8.12.2 on CentOS 7


2. Create a new C/C++ project and select the project " not related to the Qt library "


Bulid system please select CMake


After the new project is completed, the CMakeLists.txt file will be generated in the path . The next time you need to open the project, open the file/project in the qtcreator menu and select the CMakeLists.txt file.


3. How to realize single-step debugging

Method 1 (recommended): The default construction method of the project is Default, which means release. It needs to be adjusted to Debug to achieve single-step breakpoint debugging.


After checking to complete Debug, please click the option "Run CMake" in the menu -> Build.


Method 2 (not recommended): Because CMake generates the Default/ release version by default. We can manually edit the CMakeLists.txt file, add at the end of the file: 
set(CMAKE_BUILD_TYPE Debug), and build again.



4. How to add C++/C source files and header files? How to add third-party dependent libraries and header files?

The only way is to manually modify the CMakeLists.txt file, see for details

CMake usage examples and finishing summary

The method of CMake processing multi-source file directory,  please pay attention to the multi-file addition method aux_source_directory

Write CMakeLists.txt for multi-directory projects (automatically add files in multiple directories)  , please pay attention to the multi-file addition method aux_source_directory

Example 1:

[html]  view plain copy  
  1. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -g -Wall -O0 -Wno-unused-variable -pthread")  
  2.   
  3. link_directories(  
  4.     $ {PROJECT_SOURCE_DIR} / lib  
  5.     /usr/lib64/mysql/  
  6. )  
  7.   
  8. find_library(MYSQL_LIB libmysqlclient.so /usr/lib64/mysql/)  
  9. IF (NOT MYSQL_LIB)  
  10.     MESSAGE(FATAL_ERROR "mysqlclient not found")  
  11. ENDIF(NOT MYSQL_LIB)  
  12.   
  13. set(net_srcs   
  14. base/timestamp.cpp  
  15. base / countdownlatch.cpp  
  16. )  

Example 2:

set(SRC_LIST main.c hello.c)
add_executable(hello ${SRC_LIST})
There is nothing wrong with writing set like this, but if there are many source files, adding the names of all the source files will be an annoying job. A more hassle-free method is to use the aux_source_directory command, which will find all source files in the specified directory and store the result in the specified variable name. Its syntax is as follows: aux_source_directory(<dir> <variable>)
aux_source_directory(.DIRSRCS)
add_executable(hello ${DIRSRCS})

To learn CMake, please refer to the article "CMake Practice", which aims to guide users to use CMake quickly. If you need more detailed content, please read the article "CMake Practice". Download path: http://sewm.pku.edu.cn/src/paradise/reference/CMake%20Practice.pdf


5. How to realize remote debugging

Please visit the companion article "Using Qt Creator as a Linux IDE instead of Vim: Implementing Remote Deployment and Debugging of Two Linux Computers (One Computer with a Desktop System, and One Computer Without a Desktop System)" at http://blog. csdn.net/libaineu2004/article/details/62423830

Note: The target path generated by CMake remotely is /root/xxx by default. You can manually modify the CMakeLists.txt file to change the output path, SET(EXECUTABLE_OUTPUT_PATH "***"). In this way, the paths of the development machine and the target machine will have generated results. My actual measurement result is that it seems that there is a home directory in the path, but the target machine will not work? For example, SET(EXECUTABLE_OUTPUT_PATH "/home/12/"), the result file development machine is there, but the target machine is not, but a /12 folder will be generated in the root directory. For another example , the "/home/firecat/test" target machine is not there, but the "test" folder is generated in the root directory.

[html]  view plain copy  
  1. cmake_minimum_required(VERSION 2.8)  
  2.   
  3. project(untitled)  
  4. add_executable(${PROJECT_NAME} "main.cpp" "test.cpp")  
  5. ##SET(EXECUTABLE_OUTPUT_PATH "/home/firecat/test/")  
  6. SET(EXECUTABLE_OUTPUT_PATH "/hellotest/12/34")  

Part 2: Debugging the CMake project ORBSLAM2 with QT

//EVERYTHING

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324813438&siteId=291194637