Libraries, And Dependencies

Libraries And Executables

$ cmake  ~/work/jfasch-home/trainings/material/soup/cmake/05-static-libraries/
...
$ make
[ 57%] Linking C executable hello-first
/usr/bin/ld: CMakeFiles/hello-first.dir/hello-first.c.o: in function `main':
hello-first.c:(.text+0x10): undefined reference to `hello'
/usr/bin/ld: hello-first.c:(.text+0x29): undefined reference to `hello_name'
collect2: error: ld returned 1 exit status

⟶ Dependencies!

Targets And Dependencies

  • Executables depend on libraries

  • dependencies

  • hello-first depends on hello

  • hello-second depends on hello

TARGET_LINK_LIBRARIES(hello-first hello)      # <--- "hello-first" depends on "hello"
TARGET_LINK_LIBRARIES(hello-second hello)     # <--- "hello-second" depends on "hello"
  • Executables may depend on libraries

  • Libraries may depend on libraries

  • (Nothing ever depends on an executable)

  • ⟶ Directed Acyclic Graph (DAG)

Visualizing Dependencies

  • Project sanity: knowing your dependencies

  • Graphviz package

Generating dot files
$ pwd
/tmp/build
$ cmake --graphviz=Demo.dot ~/work/jfasch-home/trainings/material/soup/cmake/05-static-libraries/
$ ls -l *.dot*
-rw-r--r--. 1 jfasch jfasch 1260 Jul 13 19:31 Demo.dot
-rw-r--r--. 1 jfasch jfasch  336 Jul 13 19:31 Demo.dot.hello.dependers
-rw-r--r--. 1 jfasch jfasch  222 Jul 13 19:31 Demo.dot.hello-first
-rw-r--r--. 1 jfasch jfasch  225 Jul 13 19:31 Demo.dot.hello-second
Convert into viewable image
$ dot -Tpng Demo.dot > Demo.png
../../../../../_images/Demo.png