C++ linker presentation
This commit is contained in:
33
cpplinker/04_static_linking/build.sh
Normal file
33
cpplinker/04_static_linking/build.sh
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
echo "=== Compile object files ==="
|
||||
g++ -std=c++17 -c vec.cpp -o vec.o
|
||||
g++ -std=c++17 -c mat.cpp -o mat.o
|
||||
|
||||
echo ""
|
||||
echo "=== Create static library (archive) ==="
|
||||
ar rcs libmymath.a vec.o mat.o
|
||||
echo "Created libmymath.a"
|
||||
|
||||
echo ""
|
||||
echo "=== Inspect archive contents ==="
|
||||
ar t libmymath.a
|
||||
|
||||
echo ""
|
||||
echo "=== Symbols in the archive ==="
|
||||
nm -C -g libmymath.a
|
||||
|
||||
echo ""
|
||||
echo "=== Compile and link main against the static library ==="
|
||||
g++ -std=c++17 -c main.cpp -o main.o
|
||||
g++ main.o -L. -lmymath -o app
|
||||
echo "Created app"
|
||||
|
||||
echo ""
|
||||
echo "=== Check dynamic dependencies ==="
|
||||
ldd app || echo "(ldd not available or statically linked)"
|
||||
|
||||
echo ""
|
||||
echo "=== Run ==="
|
||||
./app
|
||||
Reference in New Issue
Block a user