Programowanie w systemie UNIX/depend

Z Wikibooks, biblioteki wolnych podręczników.
Przejdź do nawigacji Przejdź do wyszukiwania

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

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


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.[4]


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.[5]

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

Biblioteka

  • pakiety
    • dev
    • non-dev

Program[edytuj]

wykonywalny[edytuj]

Za pomocą komendy ldd[6]

 ldd /path/to/program

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

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

lub [8][9]

 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 : [10]

  • AC_SEARCH_LIBS (
  • AC_CHECK_HEADERS
  • PKG_CHECK_MODULES




czynny proces[edytuj]

  sudo pldd <PID>
 sudo pmap <PID>

biblioteki[edytuj]

Biblioteki [11]

  • 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) [12]

  ldconfig -v | grep libname


Zależności bibliotek dzielonych[13]


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

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: [15]

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


Jak wyszukiwać pakiety w Ubuntu ?[edytuj]

Narzędzie z Cmake:[16]

find_package(<Package> [version])

Inne spospby[17]

apt-cache showpkg apache2 
sudo aptitude search <package_name>

repozytoria pakietów[edytuj]

Lista [18]

  • 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 [19]

 apt-file search fontconfig/fontconfig.h

lub [20]

 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.")[21]

 apt-rdepends package

odwrotne[edytuj]

Pakiety zależne od pakietu (reverse dependencies):

 apt-cache rdepends package-name

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

  • snap[22]
  • live OS: uruchomić system bez instalacji za pomoca live CD lub usb
  • emulator
  • maszyna virtualna[23][24]

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