Developing C and C++ applications in RHEL 8 Red Hat Enterprise Linux 8 Setting up a developer workstation, and developing and debugging C and C++ applications in Red Hat Enterprise Linux 8 Red Hat Customer Content Services

Commands:
subscription-manager repos --enable rhel-8-for-USD(uname -i)-baseos-debug-rpms subscription-manager repos --enable rhel-8-for-USD(uname -i)-baseos-source-rpms subscription-manager repos --enable rhel-8-for-USD(uname -i)-appstream-debug-rpms subscription-manager repos --enable rhel-8-for-USD(uname -i)-appstream-source-rpms
yum install git
git config --global user.name " Full Name " git config --global user.email " email@example.com "
git config --global core.editor command
man git man gittutorial man gittutorial-2
yum group install "Development Tools"
yum install llvm-toolset
yum install gcc-gfortran
yum install gdb valgrind systemtap ltrace strace
yum install yum-utils
stap-prep
yum install perf papi pcp-zeroconf valgrind strace sysstat systemtap
stap-prep
systemctl enable pmcd && systemctl start pmcd
man gcc
gcc -c source.c another_source.c
gcc ... -g
man gcc
man gcc
gcc ... -O2 -g -Wall -Wl,-z,now,-z,relro -fstack-protector-strong -fstack-clash-protection -D_FORTIFY_SOURCE=2
gcc ... -Walloc-zero -Walloca-larger-than -Wextra -Wformat-security -Wvla-larger-than
gcc ... objfile.o another_object.o ... -o executable-file
mkdir hello-c cd hello-c
#include <stdio.h> int main() { printf("Hello, World!\n"); return 0; }
gcc hello.c -o helloworld
./helloworld Hello, World!
mkdir hello-c cd hello-c
#include <stdio.h> int main() { printf("Hello, World!\n"); return 0; }
gcc -c hello.c
gcc hello.o -o helloworld
./helloworld Hello, World!
mkdir hello-cpp cd hello-cpp
#include <iostream> int main() { std::cout << "Hello, World!\n"; return 0; }
g++ hello.cpp -o helloworld
./helloworld Hello, World!
mkdir hello-cpp cd hello-cpp
#include <iostream> int main() { std::cout << "Hello, World!\n"; return 0; }
g++ -c hello.cpp
g++ hello.o -o helloworld
./helloworld Hello, World!
gcc ... -l foo
gcc ... -I include_path
gcc ... -L library_path -l foo
gcc ... -I header_path -c
gcc ... -L library_path -l foo
./program
gcc ... -L library_path -l foo
gcc ... -L library_path -l foo -Wl,-rpath= library_path
./program
export LD_LIBRARY_PATH= library_path :USDLD_LIBRARY_PATH ./program
man ld.so
cat /etc/ld.so.conf
ldconfig -v
gcc ... path/to/libfoo.a
gcc ... -Wl,-Bstatic -l first -Wl,-Bdynamic -l second
gcc ... -l foo
objdump -p somelibrary | grep SONAME
gcc ... -c -fPIC some_file.c
gcc -shared -o libfoo.so.x.y -Wl,-soname, libfoo.so.x some_file.o
cp libfoo.so.x.y /usr/lib64
ln -s libfoo.so.x.y libfoo.so.x ln -s libfoo.so.x libfoo.so
gcc -c source_file.c
ar rcs lib foo .a source_file.o
nm libfoo.a
gcc ... -l foo
man ar
all: hello hello: hello.o gcc hello.o -o hello hello.o: hello.c gcc -c hello.c -o hello.o
CC=gcc CFLAGS=-c -Wall SOURCE=hello.c OBJ=USD(SOURCE:.c=.o) EXE=hello all: USD(SOURCE) USD(EXE) USD(EXE): USD(OBJ) USD(CC) USD(OBJ) -o USD@ %.o: %.c USD(CC) USD(CFLAGS) USD< -o USD@ clean: rm -rf USD(OBJ) USD(EXE)
mkdir hellomake cd hellomake
#include <stdio.h> int main(int argc, char *argv[]) { printf("Hello, World!\n"); return 0; }
CC=gcc CFLAGS=-c -Wall SOURCE=hello.c OBJ=USD(SOURCE:.c=.o) EXE=hello all: USD(SOURCE) USD(EXE) USD(EXE): USD(OBJ) USD(CC) USD(OBJ) -o USD@ %.o: %.c USD(CC) USD(CFLAGS) USD< -o USD@ clean: rm -rf USD(OBJ) USD(EXE)
make gcc -c -Wall hello.c -o hello.o gcc hello.o -o hello
./hello Hello, World!
make clean rm -rf hello.o hello
man make info make
man gcc
gcc ... -g
man gcc
gdb -q /bin/ls Reading symbols from /bin/ls...Reading symbols from .gnu_debugdata for /usr/bin/ls...(no debugging symbols found)...done. (no debugging symbols found)...done. Missing separate debuginfos, use: dnf debuginfo-install coreutils-8.30-6.el8.x86_64 (gdb)
(gdb) q
dnf debuginfo-install coreutils-8.30-6.el8.x86_64
which less /usr/bin/less
locate libz | grep so /usr/lib64/libz.so.1 /usr/lib64/libz.so.1.2.11
yum install mlocate updatedb
rpm -qf /usr/lib64/libz.so.1.2.7 zlib-1.2.11-10.el8.x86_64
debuginfo-install zlib-1.2.11-10.el8.x86_64
gdb program
ps -C program -o pid h pid
gdb -p pid
(gdb) shell ps -C program -o pid h pid
(gdb) attach pid
(gdb) file path/to/program
(gdb) help info
(gdb) br file:line
(gdb) br line
(gdb) br function_name
(gdb) br file:line if condition
(gdb) info br
(gdb) delete number
(gdb) clear file:line
(gdb) watch expression
(gdb) rwatch expression
(gdb) awatch expression
(gdb) info br
(gdb) delete num
strace -fvttTyy -s 256 -e trace= call program
ps -C program (...) strace -fvttTyy -s 256 -e trace= call -p pid
strace ... |& tee your_log_file.log
man strace
ltrace -f -l library -e function program
ps -C program (...) ltrace -f -l library -e function program -p pid
ltrace ... |& tee your_log_file.log
man ltrace
ps -aux
stap /usr/share/systemtap/examples/process/strace.stp -x pid
(gdb) catch syscall syscall-name
(gdb) r
(gdb) c
(gdb) catch signal signal-type
(gdb) r
(gdb) c
ulimit -a
DumpCore=yes DefaultLimitCORE=infinity
systemctl daemon-reexec
ulimit -c unlimited
yum install sos
sosreport
coredumpctl list executable-name coredumpctl dump executable-name > /path/to/file-for-export
eu-unstrip -n --core= ./core.9814 0x400000+0x207000 2818b2009547f780a5639c904cded443e564973e@0x400284 /usr/bin/sleep /usr/lib/debug/bin/sleep.debug [exe] 0x7fff26fff000+0x1000 1e2a683b7d877576970e4275d41a6aaec280795e@0x7fff26fff340 . - linux-vdso.so.1 0x35e7e00000+0x3b6000 374add1ead31ccb449779bc7ee7877de3377e5ad@0x35e7e00280 /usr/lib64/libc-2.14.90.so /usr/lib/debug/lib64/libc-2.14.90.so.debug libc.so.6 0x35e7a00000+0x224000 3ed9e61c2b7e707ce244816335776afa2ad0307d@0x35e7a001d8 /usr/lib64/ld-2.14.90.so /usr/lib/debug/lib64/ld-2.14.90.so.debug ld-linux-x86-64.so.2
eu-readelf -n executable_file
gdb -e executable_file -c core_file
(gdb) symbol-file program.debug
sysctl kernel.core_pattern
kernel.core_pattern = |/usr/lib/systemd/systemd-coredump
pgrep -a executable-name-fragment
PID command-line
pgrep -a bc 5459 bc
kill -ABRT PID
coredumpctl list PID
coredumpctl list 5459 TIME PID UID GID SIG COREFILE EXE Thu 2019-11-07 15:14:46 CET 5459 1000 1000 6 present /usr/bin/bc
coredumpctl info PID
coredumpctl debug PID
Missing separate debuginfos, use: dnf debuginfo-install bc-1.07.1-5.el8.x86_64
coredumpctl dump PID > /path/to/file_for_export
ps -C some-program
gcore -o filename pid
sosreport
(gdb) set use-coredump-filter off
(gdb) set dump-excluded-mappings on
(gdb) gcore core-file
gdbserver --multi :1234 gdb -batch -ex 'target extended-remote :1234' -ex 'set remote exec-file /bin/echo' -ex 'file /bin/echo' -ex 'run /*' /*
gdbserver --multi :1234 gdb -batch -ex 'target extended-remote :1234' -ex 'set remote exec-file /bin/echo' -ex 'file /bin/echo' -ex 'run /*' /bin /boot (...) /tmp /usr /var
(gdb) maintenance print symbols /tmp/out main.c
maint print symbols [-pc address ] [--] [ filename ] maint print symbols [-objfile objfile ] [-source source ] [--] [ filename ] maint print psymbols [-objfile objfile ] [-pc address ] [--] [ filename ] maint print psymbols [-objfile objfile ] [-source source ] [--] [ filename ] maint print msymbols [-objfile objfile ] [--] [ filename ]
debuginfo-install coreutils gdb -batch -ex 'file echo' -ex start -ex 'add-inferior' -ex 'inferior 2' -ex 'file echo' -ex start -ex 'info threads' -ex 'pring USD_thread' -ex 'inferior 1' -ex 'pring USD_thread' (...) Id Target Id Frame * 2 process 203923 "echo" main (argc=1, argv=0x7fffffffdb88) at src/echo.c:109 1 process 203914 "echo" main (argc=1, argv=0x7fffffffdb88) at src/echo.c:109 USD1 = 2 (...) USD2 = 1
dnf debuginfo-install coreutils gdb -batch -ex 'file echo' -ex start -ex 'add-inferior' -ex 'inferior 2' -ex 'file echo' -ex start -ex 'info threads' -ex 'pring USD_thread' -ex 'inferior 1' -ex 'pring USD_thread' (...) Id Target Id Frame 1.1 process 4106488 "echo" main (argc=1, argv=0x7fffffffce58) at ../src/echo.c:109 * 2.1 process 4106494 "echo" main (argc=1, argv=0x7fffffffce58) at ../src/echo.c:109 USD1 = 1 (...) USD2 = 1
yum install gcc-toolset- N
yum list available gcc-toolset- N -\*
yum install package_name
yum install gcc-toolset-13-annobin-annocheck gcc-toolset-13-binutils-devel
yum remove gcc-toolset- N \*
scl enable gcc-toolset- N tool
scl enable gcc-toolset- N bash
scl enable gcc-toolset-9 'gcc -lsomelib objfile.o'
scl enable gcc-toolset-9 'gcc objfile.o -lsomelib'
scl enable gcc-toolset-9 'ld -lsomelib objfile.o'
scl enable gcc-toolset-9 'ld objfile.o -lsomelib'
scl enable gcc-toolset-10 'gcc -lsomelib objfile.o'
scl enable gcc-toolset-10 'gcc objfile.o -lsomelib'
scl enable gcc-toolset-10 'ld -lsomelib objfile.o'
scl enable gcc-toolset-10 'ld objfile.o -lsomelib'
scl enable gcc-toolset-11 'gcc -lsomelib objfile.o'
scl enable gcc-toolset-11 'gcc objfile.o -lsomelib'
scl enable gcc-toolset-11 'ld -lsomelib objfile.o'
scl enable gcc-toolset-11 'ld objfile.o -lsomelib'
scl enable gcc-toolset-12 'gcc -lsomelib objfile.o'
scl enable gcc-toolset-12 'gcc objfile.o -lsomelib'
scl enable gcc-toolset-12 'ld -lsomelib objfile.o'
scl enable gcc-toolset-12 'ld objfile.o -lsomelib'
cc1: fatal error: inaccessible plugin file opt/rh/gcc-toolset-12/root/usr/lib/gcc/ architecture -linux-gnu/12/plugin/gcc-annobin.so expanded from short plugin name gcc-annobin: No such file or directory
cd /opt/rh/gcc-toolset-12/root/usr/lib/gcc/ architecture -linux-gnu/12/plugin ln -s annobin.so gcc-annobin.so
scl enable gcc-toolset-13 'gcc -lsomelib objfile.o'
scl enable gcc-toolset-13 'gcc objfile.o -lsomelib'
scl enable gcc-toolset-13 'ld -lsomelib objfile.o'
scl enable gcc-toolset-13 'ld objfile.o -lsomelib'
cc1: fatal error: inaccessible plugin file opt/rh/gcc-toolset-13/root/usr/lib/gcc/ architecture -linux-gnu/13/plugin/gcc-annobin.so expanded from short plugin name gcc-annobin: No such file or directory
cd /opt/rh/gcc-toolset-13/root/usr/lib/gcc/ architecture -linux-gnu/13/plugin ln -s annobin.so gcc-annobin.so
scl enable gcc-toolset-14 'gcc -lsomelib objfile.o'
scl enable gcc-toolset-14 'gcc objfile.o -lsomelib'
scl enable gcc-toolset-14 'ld -lsomelib objfile.o'
scl enable gcc-toolset-14 'ld objfile.o -lsomelib'
cc1: fatal error: inaccessible plugin file opt/rh/gcc-toolset-14/root/usr/lib/gcc/ architecture -linux-gnu/14/plugin/gcc-annobin.so expanded from short plugin name gcc-annobin: No such file or directory
cd /opt/rh/gcc-toolset-14/root/usr/lib/gcc/ architecture -linux-gnu/14/plugin ln -s annobin.so gcc-annobin.so
podman login registry.redhat.io Username: username Password: ********
podman pull registry.redhat.io/rhel8/gcc-toolset- <toolset_version> -toolchain
podman images
podman run -it image_name /bin/bash
podman login registry.redhat.io Username: username Password: ********
podman pull registry.redhat.io/rhel8/gcc-toolset-14-toolchain
podman run -it registry.redhat.io/rhel8/gcc-toolset-14-toolchain /bin/bash
bash-4.4USD gcc -v gcc version 14.2.1 20240801 (Red Hat 14.2.1-1) (GCC)
bash-4.4USD rpm -qa
gcc -fplugin=annobin
gcc -iplugindir= /path/to/directory/containing/annobin/
gcc --print-file-name=plugin
clang -fplugin= /path/to/directory/containing/annobin/
gcc -fplugin=annobin -fplugin-arg-annobin- option file-name
gcc -fplugin=annobin -fplugin-arg-annobin-verbose file-name
clang -fplugin= /path/to/directory/containing/annobin/ -Xclang -plugin-arg-annobin -Xclang option file-name
clang -fplugin=/usr/lib64/clang/10/lib/annobin.so -Xclang -plugin-arg-annobin -Xclang verbose file-name
annocheck file-name
annocheck directory-name
annocheck rpm-package-name
annocheck rpm-package-name --debug-rpm debuginfo-rpm
annocheck --enable-built-by
annocheck --enable-notes
annocheck --section-size= name
annocheck --enable-notes --disable-hardened file-name
objcopy --merge-notes file-name
cc1: fatal error: inaccessible plugin file opt/rh/gcc-toolset-12/root/usr/lib/gcc/ architecture -linux-gnu/12/plugin/gcc-annobin.so expanded from short plugin name gcc-annobin: No such file or directory
cd /opt/rh/gcc-toolset-12/root/usr/lib/gcc/ architecture -linux-gnu/12/plugin ln -s annobin.so gcc-annobin.so