Dependency Management in C++ Xavier Bonaventura BMW AG

Dependency Management in C++ Xavier Bonaventura BMW AG

Dependency management in C++ Xavier Bonaventura BMW AG. xbonaventurab limdor limdor xavierbonaventura code::dive 2019 – Wrocław, Poland – 20th November 2019 About me • I… • studied software engineering • created a 3D model visualization tool in C++ and OpenGL during my PhD https://github.com/limdor/quoniam (~10.000 LOC) (2010 - 2015) • moved to Munich to work in 2015 BMW AG – • started attending the C++ User Group Munich (MUC++) to realize that I knew nothing about C++ • decided to do this presentation about dependencies after 4 years attending to C++ meetups every month Xavier Bonaventura Bonaventura Xavier • remembered that I developed the 3D model visualization tool when I knew nothing about C++ 2 Goal Awareness and better understanding of the BMW BMW AG dependencies in your project – Xavier Bonaventura Bonaventura Xavier 3 What will we see? • Basic dependency concepts • Difference between declaration and definition • Building process BMW AG – • Execution sequence of a process • Implications of the design of a library Xavier Bonaventura Bonaventura Xavier • Examples with code 4 What are dependencies? 5 Basic concepts Build and runtime phase Library design Examples Dependencies in real life Apple pie Apples Pastry Sugar Flour Butter Egg white Lemon juice Spices Apple tree BMW AG – Butter Flour Salt Sugar Egg Lemon Milk Wheat Chicken Nutmeg Lemon tree Cow Egg Ginger Bonaventura Xavier Cinnamon 6 Chicken Basic concepts Build and runtime phase Egg Library design Examples Dependencies in real life digraph G { "apple pie" -> apples apples -> "apple tree“ ... } http://www.webgraphviz.com/ BMW BMW AG – Xavier Bonaventura Bonaventura Xavier Dependency graph 7 Basic concepts Build and runtime phase Library design Examples Direct vs indirect • Direct dependency • Indirect or transitive dependency BMW BMW AG – Xavier Bonaventura Bonaventura Xavier 8 Basic concepts Build and runtime phase Library design Examples Direct vs indirect • What happens when a dependency is missing? Apple pie Apples BMW AG Pastry Sugar Flour Butter Egg white – Lemon juice Spices Lemon Error: I could not find a lemon tree to Bonaventura Xavier make the apple pie Lemon 9 tree Basic concepts Build and runtime phase Library design Examples Direct vs indirect • What happens when a dependency is missing? Lemon Apple pie tree Apples BMW AG Pastry Sugar Flour Butter Egg white – Lemon juice Spices Lemon OK, apple pie done! Bonaventura Xavier 10 Basic concepts Build and runtime phase Library design Examples Direct vs indirect • What happens when a dependency is missing? Lemon Apple pie tree Apples BMW AG Pastry Sugar Flour Butter Egg white – Lemon juice Spices Lemon Xavier Bonaventura Bonaventura Xavier 11 Basic concepts Build and runtime phase Library design Examples Direct vs indirect • What happens when a dependency is missing? Lemon Apple pie tree Apples BMW AG Pastry Sugar Flour Butter Egg white – Spices Why do I need a lemon tree for an Bonaventura Xavier apple pie? 12 Only define direct dependencies Basic concepts Build and runtime phase Library design Examples Cyclic dependency BMW BMW AG – Xavier Bonaventura Bonaventura Xavier 13 Basic concepts Build and runtime phase Library design Examples Declaration vs definition • Declarations introduce (or re-introduce) names into the C++ program https://en.cppreference.com/w/cpp/language/declarations int add_values(int, int); BMW BMW AG – • Definitions are declarations that fully define the entity introduced by the declaration https://en.cppreference.com/w/cpp/language/definition int add_values(int a, int b) { return a + b; Bonaventura Xavier } One definition rule: Only one definition is allowed in one translation unit and in the 14 entire program Basic concepts Build and runtime phase Library design Examples Declaration vs definition extern int foo; int foo; int add_values(int, int); int add_values(int a, int b) { return a + b; } class Calculator; BMW AG class Calculator { – void add_value(); }; template<typename T> template<typename T> T add_values(T a, T b); T add_values(T a, T b) { Bonaventura Xavier return a + b; } 15 Basic concepts Build and runtime phase Library design Examples Building phase .h .h Pre processor Compiler Linker BMW AG .cpp .ii .o .exe – .cpp Pre processor .ii Compiler .o Xavier Bonaventura Bonaventura Xavier 16 .cpp Pre processor .ii Compiler .o Basic concepts Build and runtime phase Library design Examples Runtime .dll .dll .dll implicit loading explicit loading BMW BMW AG – Stopped Starting Running .exe Xavier Bonaventura Bonaventura Xavier 17 CppCon 2017: James McNellis “Everything You Ever Wanted to Know about DLLs” https://www.youtube.com/watch?v=JPQWQfDhICA Basic concepts Build and runtime phase Library design Examples Building a library .h .h .h .cpp BMW BMW AG – .h .h .cpp .cpp .h .h .h .h Bonaventura Xavier 18 library Basic concepts Build and runtime phase Library design Examples Building a static library .cpp Compiler .o .h.h .h Archiver .lib BMW BMW AG .cpp Compiler .o – .h.h .h .h.h .h .cpp Compiler .o library static library Bonaventura Xavier 19 Basic concepts Build and runtime phase Library design Examples Building a static library private .h .cpp BMW BMW AG – .h .h .cpp .cpp .h .h .h .h Bonaventura Xavier public 20 library Basic concepts Build and runtime phase Library design Examples Building a static library private private .h.h .cpp.cpp .lib .h .cpp BMW BMW AG – public public .h.h .h.h .h .h library static library Bonaventura Xavier 21 Basic concepts Build and runtime phase Library design Examples Building a library private • Where to put declarations and definitions? .h .h .cpp .cpp .h .h .cpp .cpp declarations for definitions for BMW BMW AG public entities public entities – declarations for definitions for .h .h .h .h private entities private entities public Bonaventura Xavier library 22 Forward declaration of classes help with the separation Basic concepts Build and runtime phase Library design Examples Building a library private definitions for • Where to put declarations and definitions? .h .h .cpp .cpp private entities declarations for private entities definitions for .h .h .cpp .cpp public entities BMW BMW AG – declarations for .h .h .h .h public entities public Bonaventura Xavier library 23 Forward declaration of classes help with the separation Basic concepts Build and runtime phase Library design Examples Building a static library private .h .cpp BMW BMW AG – .h .h .cpp .cpp .h .h .h .h Bonaventura Xavier public 24 library Basic concepts Build and runtime phase Library design Examples Building a dynamic library .cpp Compiler .o .h.h .h Linker .dll .cpp Compiler .o BMW BMW AG – .h.h .h .h.h .h .cpp Compiler .o library dynamic library Xavier Bonaventura Bonaventura Xavier .h.h .lib .h 25 static library Basic concepts Build and runtime phase Library design Examples Building a dynamic library private .h .cpp .h .lib BMW BMW AG – .h .h .cpp .cpp .h .h .h .h .h .h .h public Bonaventura Xavier public static library 26 dynamic library Basic concepts Build and runtime phase Library design Examples Building a dynamic library .dll .lib BMW BMW AG – .cpp .h .h .h .h public public Xavier Bonaventura Bonaventura Xavier dynamic library static library 27 10 differences between static and dynamic libraries every C++ developer should know https://www.acodersjourney.com/cplusplus-static-vs-dynamic-libraries/ Basic concepts Build and runtime phase Library design Examples Library usage .cpp Pre processor .ii Compiler .o Linker .h BMW BMW AG .h.h .dll .h.h .dll .h.h .lib – .h .h .h dynamic library dynamic library static library Xavier Bonaventura Bonaventura Xavier Running Starting Stopped 28 .exe Basic concepts Build and runtime phase Library design Examples Installing clang $ pacman -S mingw-w64-x86_64-clang resolving dependencies... looking for conflicting packages... Packages (18) mingw-w64-x86_64-binutils-2.32-3 mingw-w64-x86_64-crt-git-7.0.0.5524.2346384e-1 mingw-w64-x86_64-gcc-9.2.0-2 mingw-w64-x86_64-gcc-libs-9.2.0-2 mingw-w64-x86_64-gmp-6.1.2-1 mingw-w64-x86_64-headers-git-7.0.0.5524.2346384e-1 mingw-w64-x86_64-isl-0.21-1 mingw-w64-x86_64-libffi-3.2.1-4 mingw-w64-x86_64-libiconv-1.16-1 mingw-w64-x86_64-libwinpthread-git-7.0.0.5522.977a9720-1 mingw-w64-x86_64-llvm-8.0.1-3 mingw-w64-x86_64-mpc-1.1.0-1 mingw-w64-x86_64-mpfr-4.0.2-2 mingw-w64-x86_64-windows-default-manifest-6.4-3 mingw-w64-x86_64-winpthreads-git-7.0.0.5522.977a9720-1 mingw-w64-x86_64-z3-4.8.6-1 mingw-w64-x86_64-zlib-1.2.11-7 mingw-w64-x86_64-clang-8.0.1-3 Total Download Size: 436.85 MiB Total Installed Size: 2346.90 MiB 29 Basic concepts Build and runtime phase Library design Examples Installing clang $ pactree mingw-w64-x86_64-clang mingw-w64-x86_64-clang ├─mingw-w64-x86_64-llvm provides mingw-w64-x86_64-llvm=8.0.1-3 │ ├─mingw-w64-x86_64-libffi │ └─mingw-w64-x86_64-gcc-libs │ ├─mingw-w64-x86_64-gmp │ ├─mingw-w64-x86_64-mpc │ │ └─mingw-w64-x86_64-mpfr │ │ └─mingw-w64-x86_64-gmp │ ├─mingw-w64-x86_64-mpfr │ └─mingw-w64-x86_64-libwinpthread-git provides mingw-w64-x86_64-libwinpthread ├─mingw-w64-x86_64-gcc │ ├─mingw-w64-x86_64-binutils │ │ ├─mingw-w64-x86_64-libiconv │ │ └─mingw-w64-x86_64-zlib │ ├─mingw-w64-x86_64-crt-git provides mingw-w64-x86_64-crt │ │ └─mingw-w64-x86_64-headers-git │ ├─mingw-w64-x86_64-headers-git provides mingw-w64-x86_64-headers │ ├─mingw-w64-x86_64-isl │ ├─mingw-w64-x86_64-libiconv │ ├─mingw-w64-x86_64-mpc │ ├─mingw-w64-x86_64-gcc-libs provides mingw-w64-x86_64-gcc-libs=9.2.0-2 │ ├─mingw-w64-x86_64-windows-default-manifest │ ├─mingw-w64-x86_64-winpthreads-git provides mingw-w64-x86_64-winpthreads

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    38 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us