[Share Experiences] C/C++ programming environment construction
Tofloor
poster avatar
yanjuner
Super Moderator
2023-12-14 22:18
Author

Basic environment#

translater#

You first need to install some basic software packages, which are necessary to compile C/C++ programs.

Shell

sudo apt install build-essential
Of course, you can also install llvm, which is also a C/C++ compiler. Its advantage is that it can compile languages other than C/C++, such as Rust, Go, Swift, etc.

Shell

sudo apt install llvm # llvm backend compiler
sudo apt install clang # clang front-end compiler

Debugging tools#

Debugging tools are essential tools for programming. They can help us quickly locate program errors and improve the running efficiency of the program.

Shell

sudo apt install gdb  # gdb debugger
sudo apt install valgrind  # valgrind memory checking tool

Static analysis tools#

Static analysis tools can help us check program errors, such as memory leaks, null pointer access, etc.

Shell

sudo apt install cppcheck  # cppcheck static analysis tool
sudo apt install clang-tidy  # clang-tidy static analysis tool

Code formatting tools#

Code formatting tools can help us format the code to make the code style unified and improve the readability of the code.

Shell

sudo apt install clang-format  # clang-format code formatting tool

clang-format can be configured using a configuration file. The deepin community provides a configuration file that conforms to the deepin code style. You can find it here . However, it is recommended not to rely on this configuration file because this configuration file is based on the deepin code style. If your coding style is not deepin, then this configuration file is not suitable for you.

It is very important to have a good coding style. It can improve code readability, maintainability, scalability, reusability, testability, etc., so you should develop a coding style yourself and then use clang-format to format your code.

However, you should not rely too much on tools, because tools are extensions of humans, not replacements of humans. When clang-format cannot meet your needs, you should modify the code yourself.

.clang-formatFor details on the configuration file, please refer to the official documentation.

Code inspection tools#

Code inspection tools can help us check code errors, such as unused variables, uninitialized variables, etc.

Shell

sudo apt install clang-check  # clang-check code inspection tool

code coverage tool#

Code coverage tools can help us check code coverage, such as which codes have not been tested.

Shell

sudo apt install lcov  # lcov code coverage tool

Code compression tool#

Code compression tools can help us compress code so that the code takes up less space.

Shell

sudo apt install upx  # upx code compression tool

Build tools#

Build tools can help us build projects, such as compiling, linking, installation, etc.

Shell

sudo apt install cmake  # cmake build tool
sudo apt install meson  # meson build tool
sudo apt install ninja-build  # ninja build tools

text editor#

In fact, after the above software packages are installed, you can start writing C/C++ programs, but you also need a text editor. This text editor can be any, such as gedit, vim, emacs, etc. Here as a recommendation, I recommend several text editors

because#

Vim is a very powerful text editor with very powerful functions, but its learning curve is also very steep, so if you are a beginner, I do not recommend you to use vim.

Shell

sudo apt install vim

emacs#

emacs is a very powerful text editor with very powerful functions, but its learning curve is also very steep, so if you are a beginner, I do not recommend you to use emacs.

Shell

sudo apt install emacs

VSCode#

VSCode is a text editor produced by Microsoft. Its functions are very powerful, and its learning curve is not very steep, so if you are a beginner, I recommend you to use VSCode.

According to the open source agreement of VSCode, deepin cannot provide the installation package of VSCode in the source, so you need to go to the official website to download the installation package and then install it manually. Or (recommended) search for VSCode in the app store and install it. (This method will add the official software source of VSCode, so it will be much more convenient to update VSCode in the future)

Notepad--#

notepad-- is an open source cross-platform text editor. Its gitee project address is: https://gitee.com/cxasm/notepad--

GOES#

IDE is an integrated development environment that can help us quickly develop programs, such as compiling, debugging, running, formatting, checking, compression, etc.

Eclipse CDT#

Eclipse CDT is an open source C/C++ development tool that can be used on Linux, Windows and Mac. It is a powerful IDE that can provide code completion, debugging, version control, building, refactoring and other functions. Eclipse CDT's plug-in ecosystem is also very rich.

Code::Blocks#

Code::Blocks is a free cross-platform C++ IDE for Linux, Windows and Mac. It provides many features, including code completion, debugging, building, version control, and more. Code::Blocks' user interface is simple and easy to use, making it suitable for beginners and intermediate developers.

Qt Creator#

Qt Creator is a cross-platform IDE based on the Qt library, suitable for C++ and QML development. It provides an integrated debugger and code editor, and supports code completion, code templates, automatic refactoring and other functions. Qt Creator can also be used to develop GUI applications.

KDevelop#

KDevelop is an open source C++ IDE that is part of the KDE development environment and is suitable for Linux and other UNIX operating systems. It provides code completion, debugging, version control, syntax checking and other functions, and can also integrate other development tools and external applications.

NetBeans#

NetBeans is a free cross-platform IDE for C++, Java and other programming languages. It provides code completion, debugging, version control, GUI development tools and other functions, which can help developers quickly develop applications

CLion#

CLion is a C/C++ IDE based on IntelliJ IDEA, available for Linux, Windows and Mac. It provides code completion, debugging, version control, building, refactoring and other functions, and can also integrate other development tools and external applications. CLion is a paid software. If you are a student, you can go to the official website to apply for a student license.

11.1.4 Resource Guide#

books#

C++ Primer Plus#

This is a C++ textbook that is very suitable for beginners. It explains in detail the concepts of basic syntax, data types, functions, classes and objects of C++. It also has a large number of exercises and cases, which can help readers better understand and master C++. .

Effective C++ series#

This is a series of books written by the famous C++ expert Scott Meyers, which introduces in detail some advanced features and best practices of C++, which can help readers write efficient, robust, and easy-to-maintain C++ code.

C++ Primer#

This is a very popular C++ textbook. It introduces the language features, standard library, templates, etc. of C++ in detail. It is suitable for readers with a certain programming foundation.

The C++ Programming Language#

This is an authoritative textbook written by Bjarne Stroustrup, the father of C++. It introduces the language design and application of C++ in detail, and can help readers deeply understand the characteristics and design ideas of C++.

website#

C++ Reference#

This is an online C++ reference document that can help readers find C++ syntax, standard libraries, features, etc., which is very convenient.

C++ knowledge video#

There are many university C++ courses on domestic video websites, which can help readers learn C++.

C++/C UI library#

Qt#

Qt is a cross-platform C++ library that can be used to develop desktop applications, mobile applications, and embedded systems. Qt provides a wealth of UI components to help developers quickly develop GUI applications. See: Qt

DTK#

DTK is a cross-platform C++ library based on Qt, which provides a rich set of UI components to help developers quickly develop GUI applications. The goal of DTK is to provide a simple, easy-to-use, and efficient C++ library that can help developers quickly develop GUI applications.

For details, see: 11.5.DTK programming environment construction

EasyX#

EasyX, full name: "EasyX Graphics Library for C++". Because it uses static compilation and does not rely on any dll, it has ultra-low learning costs and is loved by many developers.

Environment setup under sdeepin: EasyX environment setup under deepin

Reply Favorite View the author
All Replies
s***[email protected]
deepin
2024-03-09 16:58
#1

As for LLVM, it’s a powerful compiler infrastructure that supports a wide range of programming languages. clang is the front-end compiler for llvm and is used for compiling C, C++, and Objective-C programs.

Here’s how you can install llvm and clang using the shell commands:

sudo apt install llvm # Install llvm backend compiler
sudo apt install clang # Install clang front-end compiler

Reply View the author