#!/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