Eclipse CDT preliminary use tutorial

I have used Source insight and VS. I feel that it’s useless if it doesn’t work well, so I haven’t studied it in depth. I haven’t used other such as Code::Blocks, vim, Clion, Emacs, and it’s not easy to comment. Anyway, I use Eclipse is very comfortable to use. I will share with you here and provide one more choice. If you are just learning C language or your current IDE is uncomfortable, you can try Eclipse.

1. Appearance

Main interface
Insert picture description here

The debugging interface and sub-windows are all draggable, and can be configured to suit your preferences
Insert picture description here

2. Installation

Because Eclipse is developed in Java, you need to install JDK before installing Eclipse. There are many online tutorials that I won’t talk about. Native Eclipse only supports Java, so you usually need to install a CDT plug-in for C/C++ development. But now the official has integrated the CDT plug-in into the installation package, you can download it on the official website
https://www.eclipse.org/downloads/

Select Eclipse IDE for C/C++ Developers during installation.

3. Interface configuration

You can download your favorite themes from the following website

http://www.eclipsecolorthemes.org/

Then press the following menu File->Import->Prefrence to import the previously downloaded theme file. This theme is mainly background and grammatical color matching, and there are some other places that need to be fine-tuned.

Set font size
windows->Prefrence->General->Editors->Text Editors->Colors and Fonts

Related color configuration
Selected text color:
windows->Prefrence->General->Editors->Text Editors:
Section Foreground Color
Section Background Color

Keyword color at the mouse stop:
windows->Prefrence->General->Editors->Text Editors->Annotation:
C/C++ Occurrence
C/C++ Write Occurrence

Color during single step debugging:
windows->Prefrence->General->Editors->Text Editors->Annotation:
Debug Call Stack
Debug Current Instruction Pointor

Keyword search color:
windows->Prefrence->General->Editors->Text Editors->Annotation:
Search Result
Other grammatical error warnings or spelling errors can be set under the Annotation tab

The background color of the blocked code:
windows->Prefrence->C/C+±>Editor->Inactive code highlight

Other configuration
When you move the mouse to the variable during debugging, the related information of the variable can be displayed, or you can display more detailed information in windows->Prefrence->C/C+±>Debug->GDB->Use enhanced debug hover

If the file exceeds 5000 lines and cannot be jumped, you can set and change it in windows->Prefrence->C/C+±>Editor->Scalabilitys

4. Build the project

Eclipse is an IDE without a compiler, which is equivalent to an empty shell. The compiler needs to be installed separately. Here, msys2 is recommended. After installing this platform, you can basically use a large number of libraries under the Linux platform. You can refer to the following blogger Written tutorial installation:

https://blog.csdn.net/qiuzhiqian1990/article/details/56671839

With msys2 after which you can install gcc, gdb, make other tools, but do not know Eclipse directory where gcc, so to add the path in the Path environment variables "in your directory \ msys32 \ usr \ bin;"
Then you You can create a new project, File->New->C Project, select Empty Project as the project type in this window, and Cygwin gcc as the tool chain, and then you can create a new .c file to compile.

A better part of Eclipse is that the files in the project directory and the local files where the project is located automatically correspond, so after copying other code files to the local directory, refresh them in the directory bar on the left. Of course, you can also copy or drag directly. Move to the table of contents. If the project already exists, directly File->Import and select Existing Project into Workspace.

When debugging for the first time, the file cannot be found. At this time, you need to set the path mapping to debug. This is in Run->Debug Configurations, select the exe file you debugged on the left, right-click the Source tab, click the Add button, select Path Mapping, and create a new mapping from e\ to E:\.

4. Practical functions
Basic functions:

  • Press F3 or right-click Open Declaration to jump to the definition of the function or variable
  • Right-click Open Call hierarchy to display function calls
  • Select the keyword and right click Search Text to search or search in Search->File in the menu bar. It is recommended to drag the search and function call window from the bottom to the right
  • ctrl+/ Shortcut key: batch comment or cancel comment
  • Alt+/ Shortcut key: Type the first few letters, if the word already exists in the code, it will be automatically completed
  • After entering .and ->, the member variables in the structure will be automatically displayed for quick selection
  • Right-click Source Format to adjust the code style of the entire file. The code style can be set in windows->Prefrence->C/C+±>Code Style->Formatterl
  • Right-click Refactor->Rename to modify all positions of the selected variable or function name in the project
  • The left arrow button in the toolbar can go back to the place where the code was edited last time

Save: The
first save button is to save a single file, and the second save button is to save all files. Generally speaking, the first save button is used, and the second one may be prone to some misoperations. For unsaved files, * will be displayed before the file name of the label. If there are too many open files, you can enter the first letter on the right side of the label to quickly locate a file.

Makefile:
By default, the project in eclipse does not need to write a Makefile, and a Makefile is automatically generated to complete the compilation. But sometimes we also write Makefile according to the needs. At this time, we hope that eclipse will not automatically generate the makefile. You can uncheck the Gnerate Makefile automatically in the project right-click Properties->C/C++ Build, and select the file directory where the Makefile is located below . This is very useful. Generally, the Makefile in the open source code has been written. After setting it, you can directly use the Makefile in the code.

Memory error:
Generally, memory errors in programs are troublesome to debug, but in eclipse, it is very simple. When a memory error occurs during debugging, the program will directly stop at the place where the error occurred like a breakpoint.

Dynamic library debugging:
If a project depends on the dll of another project, the source code of the other project will not be seen when debugging, and the two projects can be jointly debugged in eclipse. The method is to import the other one into eclipse and recompile to generate the dll. Be sure to add the -g compilation option to export the symbol table, and then set the library dependency in the original project, right-click Properties->C/C++Build- >Settings, add the library file name and library path in the Libraries option of Cygwin C Linker, and finally under the Source tab of Run->Debug Configurations mentioned above, click the Add button, select Project, and select the project to compile the dll, so The two projects can be jointly debugged.

Let me introduce you so much first. These functions are commonly used by me. Eclipse is actually very powerful. In general, Eclipse has all the functions you can think of, and Eclipse also supports many plug-ins to meet rich customization. If there is anything wrong If you understand, you can leave a message in the comment area.

Guess you like

Origin blog.csdn.net/pfysw/article/details/102583282