Linux shared library




Home and Applets > FAQ > About Java > About Linux Shared Library

Pour une librairie nommée « hello » :

  • Sous Linux, on utilise le prefixe lib couplé à l’extension .so, soit libhello.so.
  • Sous Windows, on lui ajoute l’extension .dll, soit hello.dll.
Reprenez le contrôle à l'aide de Linux !
Bash - La variable d'environnement PATH
Les variables d'environnement

Les différents environnements console sont appelés des shells.

sh : Bourne Shell. L'ancêtre de tous les shells.

bash : Bourne Again Shell. Une amélioration du Bourne Shell, disponible par défaut sous Linux et Mac OS X.

Le shell est le programme qui gère l'invite de commandes. C'est donc le programme qui attend que vous rentriez des commandes.

Le programme qui gère bash se trouve dans /bin/bash

Le shell utilisé par défaut sous Ubuntu est bash.

Le .bashrc est le fichier de configuration du bash que Linux vous fait utiliser par défaut. Chaque personne peut avoir son .bashrc pour personnaliser son invite de commandes, ses alias, etc.


Les variables d'environnement sont des variables que l'on peut utiliser dans n'importe quel programme. On parle aussi parfois de variables globales. Vous pouvez afficher toutes celles que vous avez actuellement en mémoire avec la commande env

Pour assigner une valeur à une variable, il suffit donc d’utiliser le signe d’affectation « = ». Cette variable n'aura d'existence dans ce cas que dans le terminal où elle aura été créée. On parlera alors de « variable de shell ». Pour que cette dernière devienne une variable d'environnement et soit mise à disposition des programmes, on utilisera la commande export.

~$ export EDITOR=gedit
~$ echo $EDITOR
gedit

Pour définir ces variables de manière permanente pour la session de l'utilisateur, on utilise le fichier caché « ~/.profile » dans lequel est déjà définie la variable PATH. On pourra aussi utiliser les fichiers de bash comme « ~/.bash_profile » ou « ~/.bashrc ». Pour toute modification dans ces fichiers système, il vous faudra avoir les droits de root.

Pour qu'une variable soit définie pour l'ensemble du système, on utilisera « /etc/profile ». C'est le PATH qui est défini dans ce fichier pour tous les utilisateurs. On pourra aussi utiliser des fichiers tels que « /etc/bash.bashrc » ou « /etc/environment ».

Le PATH est une variable système qui indique où sont les programmes exécutables sur votre ordinateur. Si vous tapez echo $PATH vous aurez la liste de ces répertoires « spéciaux ». Il vous suffit donc de déplacer ou copier votre script dans un de ces répertoires. Il faut être root pour pouvoir faire cela.

Pour rendre la modification du PATH permanente, ajouter la commande dans le fichier texte caché .bashrc se trouvant dans votre dossier personnel ainsi que dans le dossier /root.

  1. Shared library
    1. Codingfreak: Creating and using shared libraries in Linux

      GCC has a list of places to look by default for shared libraries. We tell GCC where to find libXX.so with the -L option.
      gcc -o test main.c -lXX -L/home/cf/slib
      -l option tells the compiler to look for a file named libXX.so. The XX is specified by the argument immediately following the “-l”.
      -L option tells the compiler where to find the library. The path to the directory containing the shared libraries is followed by "-L". If no “-L” is specified, the compiler will search the usual locations. "-L." means looking for the shared libraries in the current directory and "-L/home/cf/lib" means looking for the shared libraries at "/opt/lib" path. You can specify as many “-l” and “-L” options as you like.
      Basically libraries are present in /usr/lib amongst other places. Static libraries (.a suffix) are incorporated into the binary at link time, whereas dynamic ones (.so suffix) are referenced by location.

    2. thegeekstuff: Intro to Linux shared libraries (How to create shared libraries)

      There are mainly three standard locations in the filesystem where a library can be placed:
      /lib
      /usr/lib
      /usr/local/lib
      The LD_LIBRARY_PATH environment variable defines where to look for the available shared objects.

    3. IBM: Anatomy of Linux dynamic libraries
    4. IBM: Writing DLLs for Linux apps
    5. IBM: Learn Linux, 101: Manage shared libraries
    6. IBM: Dissecting shared libraries

      Thus, if you specify -lexample to the linker, it looks for libexample.so which is a symbolic link to a symbolic link to the most recent version. On the other hand, when an existing program is loaded, it will try to load libexample.so.N in which N is the version to which it was originally linked.

    7. dwheeler: Program Library HOWTO
    8. YouTube: Linux understanding shared libraries
    9. stackoverflow: Difference between static and shared libraries?
    10. superuser: How do you specify the location of libraries to a binary? (linux)

      For a once-off, set the variable LD_LIBRARY_PATH to a colon-separated list of directories to search. This is analogous to PATH for executables, except that the standard system directories are additionally searched after the ones specified through the environment.

    11. apple: Dynamic library programming topics
  2. Compiling
    1. stackoverflow: Build .so file from .c file using gcc command line
    2. stackoverflow: C++ dynamic shared library on Linux
    3. Cprogramming: Shared libraries with GCC on Linux

      We have a couple of options to make the library available at runtime: we can use the environment variable LD_LIBRARY_PATH for this, or rpath.
      gcc -L/home/username/foo -Wl,-rpath=/home/username/foo -Wall -o test main.c -lfoo

      Rpath, or the run path, is a way of embedding the location of shared libraries in the executable itself, instead of relying on default locations or environment variables. We do this during the linking stage. Notice the lengthy “-Wl,-rpath=/home/username/foo” option. The -Wl portion sends comma-separated options to the linker, so we tell it to send the -rpath option to the linker with our working directory.

      What if we want to install our library so everybody on the system can use it? For that, you will need admin privileges. You will need this for two reasons: first, to put the library in a standard location, probably /usr/lib or /usr/local/lib, which normal users don’t have write access to. Second, you will need to modify the ld.so config file and cache.

    4. adp-gmbh: Creating a shared and static library with the gnu compiler [gcc]
    5. stackoverflow: Java - JNA and shared Libraries, UnsatisfiedLinkError when starting from a .jar on Linux

      On Linux you'll need to set LD_LIBRARY_PATH to include the directory containing that second shared library.

    6. YouTube: .SO shared object files in Linux, (library modules)
    7. eyrie: Shared library search paths

      The search paths for libraries come from three sources: the environment variable LD_LIBRARY_PATH (if set), any rpath encoded in the binary, and the system default search paths. They're searched in this order, and the first matching library found is used.

    8. An Introduction to GCC - for the GNU compilers gcc and g++: Shared libraries and static libraries
    9. ehuss: Shared library mini-tutorial
    10. Brad's Raspberry Pi blog: Reading from an I2C device with Java and JNA on a Raspberry Pi

      Place the resulting .so file to the same directory as the JNA JAR files.

    11. stackoverflow: How do I fix 'for loop initial declaration used outside C99 mode' GCC error?

      gcc -std=c99

    12. stackoverflow: for loop initial declaration error
    13. stackoverflow: Implicit declaration of function 'min'

      #ifndef min
      #define min(a,b) (((a) < (b)) ? (a) : (b))
      #endif

    14. askubuntu: How do I install gcc 4.8.1 on Ubuntu 13.04?
  3. Java
    1. wikihow: How to install Oracle Java JDK on Ubuntu Linux
    2. webupd8: Install Oracle Java 7 in Ubuntu via PPA repository
    3. oracle: Java control panel

      /usr/bin/ControlPanel

    4. datastax: Installing the JRE and JNA
    5. datastax: Installing the JNA on Debian or Ubuntu systems
    6. NAG: Calling C library routines from Java using the Java Native Interface
    7. developpez: Exécuter du code natif en Java : JNI vs JNA
    8. Java in 21 Days: Using native methods and libraries
    9. chilkatsoft: How to load a Java native/shared library (.so)
    10. stuf: Calling C code from Java using JNA
    11. github: JNA API 3.4.0 documentation
    12. java: JNA API 3.2.7 documentation
    13. opengamma: JNA, JNI and raw Java performance

      We first create an interface that extends the JNA Library class.

      // interface for LAPACK via JNA
      public interface LAPACKLibrary extends Library {
      LAPACKLibrary INSTANCE = (LAPACKLibrary)
      Native.loadLibrary("liblapack.so",LAPACKLibrary.class);
      LAPACKLibrary SYNC_INSTANCE = (LAPACKLibrary) Native.synchronizedLibrary(INSTANCE);
      void dgemv_(...);
      }

      then write a static initialiser in our Java class to load the native library wrapper we just created

      static {
      try {
      System.loadLibrary("<lib name>"); // no "lib" prefix or ".so" suffix
      } catch (UnsatisfiedLinkError e) {
      System.err.println("Cannot find <lib name> hooks.\n" + e);
      System.exit(1);
      }
    14. gmane: Global variable access in JNA

    15. mordroid: How to use JNA to call C/C++ API from Java

      JNA doesn't work with C++, but it works perfectly with C. In order to use JNA for C++ APIs, you have to write a C wrapper for your C++ API.

    16. januszblank: Building and loading native DLL and SO libraries into Java via JNA
    17. pbone: jna rpm build for CentOS 6
    18. astro-saada: Faire du JNI sous Eclipse
    19. askubuntu: How can I execute a .jar file from the terminal

      java -jar Minecraft.jar

    20. oracle: PATH and CLASSPATH
    21. java: Configuration ou modification de la variable système PATH
  4. Eclipse in Ubuntu
    1. YouTube: Installing Eclipse IDE with C/C++ plugin (or CDT) in Ubuntu Linux
    2. stackoverflow: How to install Eclipse with C++ in Ubuntu 12.10?

      sudo apt-get install eclipse eclipse-cdt g++

    3. YouTube: How to manually install Eclipse in Ubuntu/Linux
    4. ubuntu-fr: Documentation sur Eclipse dans Ubuntu/Linux
    5. janaxelson: Using Eclipse to cross-compile applications for embedded systems in Ubuntu
    6. YouTube: Setting up Eclipse C/C++ in Ubuntu Linux
    7. ubuntu-fr: Installer un logiciel sous Ubuntu
  5. Eclipse
    1. iandickinson: A complete beginner's guide to starting a Jena project in Eclipse
    2. avajava: How do I create an Eclipse User Library for the Tomcat jar files?
    3. avajava: Eclipse tutorials
    4. YouTube: Installing Eclipse (Kepler) for Java and C++ (MinGW and CDT) under Windows 2013/2014
    5. C/C++ Software Development with Eclipse: Installing Eclipse
    6. YouTube: Create and use dynamic libraries in Eclipse 4.4 (Luna)
    7. stackoverflow: How to compile for 32bit with Eclipse
    8. Eclipse: Specifying the JVM in eclipse.ini
    9. informit: Configuring an Eclipse Java project
  6. JNA
    1. stackoverflow: Preparing JNA for use in Eclipse

      To do this for an individual project, right click on the project in the Package Explorer, click Properties (at the bottom), click Java Build Path on the left, then the Add External Jar files. Browse to the directory with your JNA files and add those two files.

    2. Eclipse Community Forums: Using JNA in plugin

      Add jna-3.5.2.jar from Project->Properties->Java Build Path->Libraries->Add External JARS tab.

    3. Eclipse Community Forums: JNA : où placer ma librairie ?

      J'ai du redéfinir mon LD_LIBRARY_PATH dans l'environnement de debug sous Linux.

    4. Eclipse: How to import a jar in Eclipse
  7. Eclipse-CDT
    1. YouTube: Making shared library with Eclipse CDT
    2. stackoverflow: Eclipse CDT linking to shared library
    3. dr.dobb's: Cross-platform C/C++ development with Eclipse CDT
    4. YouTube: Install MinGW64 (GNU GCC) and eclipse CDT on 64bit Windows OS
    5. developpez: Développer en C ou C++ avec Eclipsee
    6. UCLA: Using Eclipse for C/C++ programming
    7. NTU: How to install Eclipse CDT 8.2 and get started

      C++ program with Makefile

    8. max.berger: Setting up Eclipse CDT on Windows, Linux/Unix, Mac OS X
    9. intel: Using Intel® C++ compiler with the Eclipse IDE on Linux
    10. C/C++ development user guide
    11. ARM: How do I use a custom gcc toolchain with Eclipse?
    12. ----------------------------------------------------------------
    13. choorucode: How to add include directory in Eclipse CDT

      Many C/C++ projects may have to use header files that are not placed in the standard include directories.

    14. choorucode: How to add library in Eclipse CDT

      The source code of a C/C++ project may need to be linked with an external shared library file.

    15. choorucode: How to add library path in Eclipse CDT

      A C/C++ project may need to be linked with library files that are not placed in the standard library path locations.

    16. ----------------------------------------------------------------
    17. eclipsesource: Shared libraries with Eclipse CDT and cygwin on Windows
    18. Linux, C++ and other Tortures: Shared libraries with Eclipse
    19. cudaverse: Eclipse with CUDA

    20. pourounas: Getting ready to develop with CUDA in Eclipse under Ubuntu

    21. skeelooslaboratory: Quickstart: CUDA using Bayreuth University CUDA toolchain for Eclipse

    22. opencv: Using OpenCV with Eclipse (plugin CDT)

      Include directory in Eclipse CDT:

    23. Using Eclipse to write a C library in C++ and package it for Debian
    24. tayefeh: Creating and using a C++ shared library with Eclipse CDT Galileo and GNU C++ compiler and linker

      Only if you would like to create a 64bit build:
      Advanced Settings -> GCC C++ Compiler -> Miscellaneous -> All Options: Add -fPIC

    25. Location, location, location: Eclipse CDT and shared libraries

    26. google: Shared libraries on Linux

      The shared library won't be available at runtime even though the compiler found it at link time.

    27. stackoverflow: Eclipse CDT not generating symbols for new projects
    28. stackoverflow: “Export” button in Eclipse CDT “Paths and Symbols” dialog?
    29. askubuntu: How to make Eclipse CDT's Linux GCC toolchain resolve C++ standard library headers?
    30. codeproject: C++ Development using eclipse IDE– Starters guide
    31. stephanfr: Debugging GCC in Eclipse CDT 4.2

      I use the Web Upd8 PPA repository for Ubuntu to install the JDK.

  8. CULA
    1. Gadgetron: Linux CUDA setup

      To set the path permanently, set the path in your startup file.
      For bash, edit the startup file (~/.bashrc):
      PATH=/usr/local/jdk1.7.0/bin:$PATH
      export PATH

    2. Gadgetron: Gadgetron users guide
    3. nvidia: NVIDIA CUDA getting started guide for Linux
    4. nvidia: CUDA deb package setup

      The Deb packages and the stand-alone installer installations (.run file) of the NVIDIA driver are incompatible.

      /usr/bin/nvidia-uninstall

  9. Dependencies
    1. qt-project: Show library dependencies

      Linux uses the “ldd” command to show the libraries that are linked to an executable or another shared library

    2. askubuntu: Dependency Walker for ubuntu
    3. stackoverflow: Dependency Walker equivalent for Linux?
    4. stackoverflow: How to see full 'ldd' path details, instead of “file not found”?

      find / -ls | grep libssl.so

    5. oracle: Configuring and using Chroot Jails
  10. GPU
    1. binarytides: How to get information about graphics card (GPU) on Linux

      lspci -vnn | grep VGA -A 12

    2. cyberciti: Linux find out graphics card installed in my system

      sudo apt-get install hardinfo

    3. cgl.ucsf: Update Linux graphics driver

      glxinfo | grep OpenGL

    4. superuser: Need to find out the name of the graphics card and and if driver is installed?

      lspci | grep VGA

      lsmod | grep nv

    5. askubuntu: How to install NVIDIA.run?

      sudo ./NVIDIAxxxx.run --no-x-check

  11. GRUB
    1. howtogeek: Clean up the new Ubuntu Grub2 boot menu
    2. howtogeek: How to configure the Linux Grub2 boot menu the easy way
    3. askubuntu: How do I change the GRUB boot order?
    4. dedoimedo: GRUB 2 bootloader - Full tutorial
 
[Contact me] - Last updated October 14, 2014
Copyright © 2002- pascal-man.com. All rights reserved.