summaryrefslogtreecommitdiff
path: root/schulung_tools/linking/hello/shared_library.txt
diff options
context:
space:
mode:
authorManuel Traut <manut@linutronix.de>2019-01-09 16:42:49 +0100
committerJohn Ogness <john.ogness@linutronix.de>2019-01-28 17:25:56 +0106
commitb990733af9d6a07c2130daeb5fd39c75f6804441 (patch)
tree6c5f6486948ab3c1a9ec1a0db6d045d6bb1543c4 /schulung_tools/linking/hello/shared_library.txt
parent6f5bc54bec1449b1713504950cce078b0dac47c1 (diff)
add examples for dynamic linking / loading
one example by doing it manually with an ugly Makefile, another one by using autotools. Signed-off-by: Manuel Traut <manut@linutronix.de>
Diffstat (limited to 'schulung_tools/linking/hello/shared_library.txt')
-rw-r--r--schulung_tools/linking/hello/shared_library.txt20
1 files changed, 20 insertions, 0 deletions
diff --git a/schulung_tools/linking/hello/shared_library.txt b/schulung_tools/linking/hello/shared_library.txt
new file mode 100644
index 0000000..1dd0f9f
--- /dev/null
+++ b/schulung_tools/linking/hello/shared_library.txt
@@ -0,0 +1,20 @@
+# build shared library
+gcc -fPIC -shared -Wl,-soname,libhello.so.1 -olibhello.so.1.0.3 libhello.c
+
+# install shared library
+sudo mkdir -p /opt/myfirma/lib
+sudo cp libhello.so.1.0.3 /opt/myfirma/lib
+
+# add custom path to dynamic loader search path
+echo "/opt/myfirma/lib" | sudo tee /etc/ld.so.conf.d/myfirma.conf
+
+# refresh dynamic loader cache
+sudo ldconfig
+
+# verify custom library is in cache
+/sbin/ldconfig -p | grep libhello.so.1
+
+# compile program using custom library
+ln -s /opt/myfirma/lib/libhello.so.1.0.3 libhello.so
+gcc -L. -ohello hello.c -lhello
+rm libhello.so