C++ linker presentation

This commit is contained in:
2026-02-24 10:21:15 +01:00
parent 0fda0d75fb
commit 6f3d98f388
32 changed files with 788 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
#!/bin/bash
set -e
echo "=== Compile with -fPIC for position-independent code ==="
g++ -std=c++17 -fPIC -c vec.cpp -o vec.o
g++ -std=c++17 -fPIC -c mat.cpp -o mat.o
echo ""
echo "=== Create shared library ==="
g++ -shared vec.o mat.o -o libmymath.so
echo "Created libmymath.so"
echo ""
echo "=== Symbols exported by the shared library ==="
nm -C -D libmymath.so | grep -E "vec_|mat_"
echo ""
echo "=== Compile and link main dynamically ==="
g++ -std=c++17 -c main.cpp -o main.o
g++ main.o -L. -lmymath -Wl,-rpath,'$ORIGIN' -o app
echo "Created app"
echo ""
echo "=== Runtime dependencies ==="
ldd app
echo ""
echo "=== Run ==="
./app