Programowanie w systemie UNIX/depend

Z Wikibooks, biblioteki wolnych podręczników.

Zależności ( ang dependencies)[1]

  • biblioteki
    • katalogi poszukiwań[2]
  • pakiety
    • lista zależności[3]
Piekło zależności


typy[edytuj]

Zależności[4][5] ( ang dependecies) = lista identyfikatorów innych programów, bibliotek, ...

  • Zależności wykonawcze: inne programy wymagane do uruchomienia programu
  • Zależności programistyczne: inne programy wymagane do opracowania programu, budowania programu, uruchomienia testów


Brak zależności[edytuj]

Brak zależności ( ang. zero dependency)

Zależności zwykle mają zależności, które mają zależności w nieskończoność. Wszystkie te elementy muszą być aktualizowane na wypadek luk w zabezpieczeniach, a czasami pojawia się bałagan w zależnościach od wielu wersji tej samej biblioteki. Dlatego w przypadku małej biblioteki brak zależności może być cechą.[6]

uaktualnianie systemu[edytuj]

sudo apt-get update
sudo apt-get autoremove
sudo apt-get install -f

Pierwsze polecenie zaktualizuje listę pakietów, drugie usunie wszystkie pakiety, które nie są już potrzebne, a trzecie polecenie zainstaluje wszystkie pakiety, które są potrzebne innym pakietom, ale jeszcze nie zostały zainstalowane.[7]

build-deps[edytuj]

Skrypt basha

 
#!/bin/sh

OS=`uname`
ID=
DESCR=
REL=
KERNEL=`uname -r`
MACH=`uname -m`

if [ "${OS}" = "Darwin" ] ; then
    ID='OS X'
    DESCR=`sw_vers -productName`
    build=`sw_vers -buildVersion`
    REL="`sw_vers -productVersion` ($build)"
elif [ "${OS}" = "Linux" ] ; then
    if [ "x`which lsb_release 2>/dev/null`" != "x" ] ; then
        ID=`lsb_release -s -i`
        DESCR=`lsb_release -s -d | sed s/\"//g | sed s/\ release//`
        REL=`lsb_release -s -r`
    elif [ -f /etc/redhat-release ] ; then
	ID='Red Hat'
	DESCR=`cat /etc/redhat-release | sed s/\ release//`
	REL=`cat /etc/redhat-release | sed s/.*release\ // | sed s/\ .*//`
    elif [ -f /etc/fedora-release ] ; then
	ID='Fedora'
	DESCR=`cat /etc/fedora-release | sed s/\ release//`
	REL=`cat /etc/fedora-release | sed s/.*release\ // | sed s/\ .*//`
    elif [ -f /etc/SuSE-release ] ; then
	ID='openSUSE project'
	DESCR=`cat /etc/SuSE-release | tr "\n" ' '| sed s/VERSION.*//`
	REL=`cat /etc/SuSE-release | tr "\n" ' ' | sed s/.*=\ //`
    fi
fi

echo " "
echo "      OS name: $OS"
echo " Distribution: $ID"
echo "  Description: $DESCR"
echo "      Release: $REL"
echo "       Kernel: $KERNEL"
echo " Architecture: $MACH"
echo " "

if [ "$ID" != "" ] ; then
  cat <<eof
The following pre-installation steps are required for a GR framework
software installation:

eof

fi

if [ "$ID" = "OS X" ] ; then
  cat <<eof
- Install "Xcode" via the Mac App Store and the "Xcode Command Line Tools"
- Install the latest version of XQuartz (http://xquartz.macosforge.org)
eof

elif [ "$ID" = "Red Hat" -o "$ID" = "CentOS" ] ; then
  cat <<eof
yum install gcc gcc-c++ gcc-gfortran ghostscript-devel python2 \
texlive-collection-latex texlive-dvipng cmake patch
eof

elif [ "$ID" = "Fedora" ] ; then
  cat <<eof
yum install gcc gcc-c++ gcc-gfortran ghostscript-devel python2 \
texlive-collection-latex texlive-dvipng wxGTK-devel glfw-devel zeromq3-devel \
libjpeg-turbo-devel
eof

elif [ "$ID" = "Debian" ] ; then
  cat <<eof
apt-get install libx11-dev libxft-dev libxt-dev python2.7 \
libgl1-mesa-dev libgs-dev texlive-latex3 dvipng qt4-dev-tools \
libgtk2.0-dev libwxgtk3.0-dev libglfw3-dev libzmq3-dev cmake
eof

elif [ "$ID" = "Ubuntu" ] ; then
  cat <<eof
apt-get install libx11-dev libxft-dev libxt-dev python2.7 \
libgl1-mesa-dev libgs-dev texlive-latex3 dvipng qt4-dev-tools \
libgtk2.0-dev libwxgtk2.8-dev libzmq3-dev cmake

The package libglfw-dev is too old.
eof

elif [ "$ID" = "openSUSE project" ] ; then
  cat <<eof
zypper install gcc gcc-c++ gcc-fortran libX11-devel python2 \
texlive-latex texlive-dvipng wxWidgets-devel ghostscript-devel cmake patch
eof

fi

echo " "


lib/build-deps



     OS name: Linux
Distribution: Ubuntu
 Description: Ubuntu 22.04.2 LTS
     Release: 22.04
      Kernel: 5.19.0-46-generic
Architecture: x86_64

The following pre-installation steps are required for a GR framework software installation:

Jak narysować graf zależności?[edytuj]

 I used grep and sed to extract the include graph of the source code for this project.  Then tred (which edits graph specifications to remove transitive edges. i.e, if A->B and B->C and A->C, it'll remove A->C) showed me a few of my includes were redundant.  I used dot to draw the dependencies.[8]

Jak sprawdzić zależności?[edytuj]

Biblioteka

  • pakiety
    • dev
    • non-dev

Program[edytuj]

wykonywalny[edytuj]

Za pomocą komendy ldd[9]

 ldd /path/to/program

lub bezpieczniej (program ldd może uruchamiać badany program co jest potencjalnie szkodliwe, gdy pochodzi z nieznanego źródła) [10]

 objdump -p /path/to/program | grep NEEDED

lub [11][12]

 readelf -d /bin/ls | grep 'NEEDED'

Żródła[edytuj]

Jeśli program był zainstalowany za pomocą autotools to wyszukujemy ( grep) w pliku configure.ac : [13]

  • AC_SEARCH_LIBS (
  • AC_CHECK_HEADERS
  • PKG_CHECK_MODULES




czynny proces[edytuj]

  sudo pldd <PID>
 sudo pmap <PID>

biblioteki[edytuj]

Biblioteki [14]

  • dzielone ( ang. shared library), pliki z rozszerzeniem "so"

dzielone[edytuj]

Lista bibliotek dzielonych ( ang. shared library), pliki z rozszerzeniem "so"

 ldconfig -p


Sprawdzamy czy są i jakie wersje maja zainstalowane biblioteki "libname" ( nazwa do zmiany) [15]

  ldconfig -v | grep libname


Zależności bibliotek dzielonych[16]


Jak znaleźć i dodać zainstalowaną bibliotekę do ścieżki wyszukiwania bibliotek ?[17]

sudo find / -name the_name_of_the_file.so
echo $LD_LIBRARY_PATH
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/my_library/
export LD_LIBRARY_PATH

pakiety[edytuj]

W ubuntu :

sudo apt-get build-dep <package>

lub

 dpkg -l | grep -i nazwa_paklietu
 sudo apt list --installed | grep -i nazwa_pakietu


Pakiety dev: [18]

to build things based on libfoo, you need libfoo-dev


Jak wyszukiwać pakiety w Ubuntu ?[edytuj]

Narzędzie z Cmake:[19]

find_package(<Package> [version])

Inne spospby[20]

apt-cache showpkg apache2 
sudo aptitude search <package_name>

repozytoria pakietów[edytuj]

Lista [21]

  • plik /etc/apt/sources.list
  • pliki w katalogu /etc/apt/sources.list.d/


 sudo grep -rhE ^deb /etc/apt/sources.list* 
 sudo apt-cache policy 

pakiet deb[edytuj]

Zależności pakietu za pomocą apt:

 apt-cache showpkg package-name


 apt-cache depends package-name


lub apt-file [22]

 apt-file search fontconfig/fontconfig.h

lub [23]

 dpkg -I package.deb

lub rekursywnie (zależności zależności: "it resolves dependencies recursively, i.e., not only does it show the direct dependencies of a package, but also the dependencies' dependencies.")[24]

 apt-rdepends package

odwrotne[edytuj]

Pakiety zależne od pakietu (reverse dependencies):

 apt-cache rdepends package-name

Jak uruchomić stary program na nowym systemie ?[edytuj]

  • snap[25]
  • live OS: uruchomić system bez instalacji za pomoca live CD lub usb
  • emulator
  • maszyna virtualna[26][27]

Zobacz również[edytuj]

Źródła[edytuj]

  1. askubuntu question: what-are-dependencies
  2. stackoverflow question: find-a-directory-in-shared-library-search-path
  3. ostechnix: list-dependencies-package-linux
  4. Zależność oprogramowania w wikipedii
  5. progsbase docs: programs
  6. reddit AskProgramming: why is zero dependencies seen as a good thing in
  7. askubuntu question: cant-install-several-development-libraries
  8. m-trustworthy by Claude
  9. man ldd
  10. How to check what libraries are used by a program or process on Linux Posted on August 7, 2014 by Dan Nanni
  11. unix.stackexchange question how-to-find-out-the-dynamic-libraries-executables-loads-when-run
  12. stackoverflow question how-do-i-find-the-direct-shared-object-dependencies-of-a-linux-elf-binary
  13. unix.stackexchange question: get-list-of-required-libraries-when-installing-something-from-source
  14. yolinux TUTORIAL: LibraryArchives-StaticAndDynamic
  15. linuxquestions : bash-command-to-list-installed-libraries-and-version-numbers
  16. simplified.guide: linux show-shared-library-dependency
  17. stackoverflow question: linux-error-while-loading-shared-libraries-cannot-open-shared-object-file-no-s
  18. stackoverflow question: how-to-install-gtk-development-dependencies-on-ubuntu
  19. https://cmake.org/cmake/help/book/mastering-cmake/chapter/Finding%20Packages.html
  20. makeuseof : how-to-search-for-packages-ubuntu
  21. tecadmin : view-installed-repositories-in-ubuntu
  22. apt-file command with examples by Computer Hope
  23. askubuntu question how-can-i-check-dependency-list-for-a-deb-package
  24. checking-package-dependencies-with-apt-rdepends-on-debian-ubuntu
  25. ubuntu blog: how-to-preserve-old-software-with-snaps
  26. help.ubuntu : VirtualMachines
  27. osboxes : ubuntu
  28. AutoApt