Linux shared library

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

Pour une librairie nommée «hello»:

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

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.

(A) 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 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 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:
    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 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 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
(B) 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 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. ehuss: Shared library mini-tutorial
  9. 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.

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

    gcc -std=c99

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

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

  13. askubuntu: How do I install gcc 4.8.1 on Ubuntu 13.04?
(C) 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


  4. NAG: Calling C library routines from Java using the Java Native Interface
  5. developpez: Exécuter du code natif en Java : JNI vs JNA
  6. Java in 21 Days: Using native methods and libraries
  7. chilkatsoft: How to load a Java native/shared library (.so)
  8. 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)
    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);
  9. gmane: Global variable access in JNA

  10. 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.

  11. astro-saada: Faire du JNI sous Eclipse
  12. askubuntu: How can I execute a .jar file from the terminal

    java -jar Minecraft.jar

  13. oracle: PATH and CLASSPATH
  14. java: Configuration ou modification de la variable système PATH
(D) 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. ubuntu-fr: Installer un logiciel sous Ubuntu
(E) 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. stackoverflow: How to compile for 32bit with Eclipse
  7. Eclipse: Specifying the JVM in eclipse.ini
  8. informit: Configuring an Eclipse Java project
  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
(G) Eclipse-CDT
  1. YouTube: Making shared library with Eclipse CDT
  2. stackoverflow: Eclipse CDT linking to shared library
  3. YouTube: Install MinGW64 (GNU GCC) and eclipse CDT on 64bit Windows OS
  4. developpez: Développer en C ou C++ avec Eclipsee
  5. UCLA: Using Eclipse for C/C++ programming
  6. NTU: How to install Eclipse CDT 8.2 and get started

    C++ program with Makefile

  7. max.berger: Setting up Eclipse CDT on Windows, Linux/Unix, Mac OS X
  8. intel: Using Intel® C++ compiler with the Eclipse IDE on Linux
  9. C/C++ development user guide

  10. eclipsesource: Shared libraries with Eclipse CDT and cygwin on Windows
  11. Linux, C++ and other Tortures: Shared libraries with Eclipse
  12. cudaverse: Eclipse with CUDA
  13. pourounas: Getting ready to develop with CUDA in Eclipse under Ubuntu
  14. skeelooslaboratory: Quickstart: CUDA using Bayreuth University CUDA toolchain for Eclipse
  15. opencv: Using OpenCV with Eclipse (plugin CDT)

    Include directory in Eclipse CDT:

  16. 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

  17. Location, location, location: Eclipse CDT and shared libraries
  18. google: Shared libraries on Linux

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

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

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

  1. Gadgetron: Linux CUDA setup

    To set the path permanently, set the path in your startup file.
    For bash, edit the startup file (~/.bashrc):

    export PATH
(I) 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

  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

    sudo ./ --no-x-check

  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

Solid-state NMR bibliography for:

[Contact me] - Last updated April 04, 2020
Copyright © 2002-2020 All rights reserved.