Skip to content

Linux Development Environment

Razvan Deaconescu edited this page Sep 28, 2021 · 6 revisions

The Linux Development Environment

Creating new software requires development tools such as editors, compilers and debuggers. Operating systems provide such tools, often in the form of SDKs (software development kits). An SDK provides libraries and frameworks, compilers, build automation tools to the developer. In Linux it's common for these tools to come in separate packages; however there are meta-packages (such as build-essential on Debian) that combine common development tools and allow an install all at once functionality.

In this chapter we present the essential toolchain provided by Linux to developers, i.e. the GNU toolchain. We focus on the C development environment: GCC, GDB, editors, profilers, libraries, static checkers. We introduce the POSIX API, the common interface offered by most flavours of UNIX.

The aim of this chapter is to improve the skills in using Linux/UNIX development tools. You will have a better knowledge of fixing common configuration and development issues.

Contents

source code to process: compiler, assembler, linker, loader C/C++, GCC, Clang build automation, Makefile libraries, static vs shared libraries, static vs dynamic linking debugging, segmentation fault, breakpoint, backtrace, GDB, Valgrind static and dynamic checkers, fuzzers profiling, instrumentation vs sampling cross compiling

Demos

The developer writes source code that eventually gets translated into executable code part of a software package delivered to the end user.

Source code is compiled into assembly code, the assembler assembles it into machine code as part of an object file, multiple object files and library files are linked into an executable. Executables are loaded as processes.

The Build Process

02-development-environment/hello.

Add example in a Makefile. 02-development-environment/hello

Make is a build automation tool.

There are other: CMake, Ant, Maven. May be used for other use cases, not necessarily building.

Makefile++

Implicit variables. Use linking (LDLIBS) for libcrypt. 02-development-environment/crypt

Create Makefile for multiple source code files. 02-development-environment/sock

Static / Dynamic Linking in Makefile

Do static linking and dynamic linking in Makefile. Use ldd to list dynamic dependencies on executable. 02-development-environment/hello

Debugging

A program using strcpy() does segmentation fault. Use GDB to detect cause of error by using backtrace. Use valgrind to detect issues. 02-development-environment/elven-godmother.

Profiling

Profile program by instrumenting (gprof, kcachegrind) or by sampling. Show duration for row-major / column-major source code. 02-development-environment/row-column-major

Cross-compiling

We can do cross compilation: install required Linaro toolchain and qemu package. Compile static vs dynamic, run.

wget http://releases.linaro.org/components/toolchain/binaries/7.4-2019.02/armv8l-linux-gnueabihf/gcc-linaro-7.4.1-2019.02-x86_64_armv8l-linux-gnueabihf.tar.xz
sudo apt install qemu

Tasks

Makefile

Create Makefile for written programs. 02-development-environment/server

Preprocessor in Makefile

Compile program with mutexes and spinlocks depending on pre-processor information. 02-development-environment/list-excl.

Static Checkers

Use static checkers to detect different types of index out of bounds 02-development-environment/elven-godmother.