*** Outline ***
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.
(A) Shared library- 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. - 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. - IBM: Anatomy of Linux dynamic libraries
- IBM: Writing DLLs for Linux apps
- IBM: Learn Linux, 101: Manage shared libraries
- 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.
- dwheeler: Program Library HOWTO
- YouTube: Linux understanding shared libraries
- stackoverflow: Difference between static and shared libraries?
- 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.
- apple: Dynamic library programming topics
- stackoverflow: Build .so file from .c file using gcc command line
- stackoverflow: C++ dynamic shared library on Linux
- 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. - adp-gmbh: Creating a shared and static library with the gnu compiler [gcc]
- 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.
- YouTube: .SO shared object files in Linux, (library modules)
- 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.
- ehuss: Shared library mini-tutorial
- 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.
- stackoverflow:
How do I fix 'for loop initial declaration used outside C99 mode' GCC error?
gcc -std=c99
- stackoverflow: for loop initial declaration error
- stackoverflow:
Implicit declaration of function 'min'
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif - askubuntu: How do I install gcc 4.8.1 on Ubuntu 13.04?
- wikihow: How to install Oracle Java JDK on Ubuntu Linux
- webupd8: Install Oracle Java 7 in Ubuntu via PPA repository
- oracle:
Java control panel
/usr/bin/ControlPanel
- NAG: Calling C library routines from Java using the Java Native Interface
- developpez: Exécuter du code natif en Java : JNI vs JNA
- Java in 21 Days: Using native methods and libraries
- chilkatsoft: How to load a Java native/shared library (.so)
- 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); }
- gmane:
Global variable access in JNA
- 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.
- astro-saada: Faire du JNI sous Eclipse
- askubuntu:
How can I execute a .jar file from the terminal
java -jar Minecraft.jar
- oracle: PATH and CLASSPATH
- java: Configuration ou modification de la variable système PATH
- YouTube: Installing Eclipse IDE with C/C++ plugin (or CDT) in Ubuntu Linux
- stackoverflow:
How to install Eclipse with C++ in Ubuntu 12.10?
sudo apt-get install eclipse eclipse-cdt g++
- YouTube: How to manually install Eclipse in Ubuntu/Linux
- ubuntu-fr: Documentation sur Eclipse dans Ubuntu/Linux
- janaxelson: Using Eclipse to cross-compile applications for embedded systems in Ubuntu
- ubuntu-fr: Installer un logiciel sous Ubuntu
- iandickinson: A complete beginner's guide to starting a Jena project in Eclipse
- avajava: How do I create an Eclipse User Library for the Tomcat jar files?
- avajava: Eclipse tutorials
- YouTube: Installing Eclipse (Kepler) for Java and C++ (MinGW and CDT) under Windows 2013/2014
- C/C++ Software Development with Eclipse: Installing Eclipse
- stackoverflow: How to compile for 32bit with Eclipse
- Eclipse: Specifying the JVM in eclipse.ini
- informit: Configuring an Eclipse Java project
- 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.
- Eclipse Community Forums:
Using JNA in plugin
Add jna-3.5.2.jar from Project->Properties->Java Build Path->Libraries->Add External JARS tab.
- Eclipse Community Forums:
JNA : où placer ma librairie ?
J'ai du redéfinir mon LD_LIBRARY_PATH dans l'environnement de debug sous Linux.
- Eclipse: How to import a jar in Eclipse
- YouTube: Making shared library with Eclipse CDT
- stackoverflow: Eclipse CDT linking to shared library
- YouTube: Install MinGW64 (GNU GCC) and eclipse CDT on 64bit Windows OS
- developpez: Développer en C ou C++ avec Eclipsee
- UCLA: Using Eclipse for C/C++ programming
- NTU:
How to install Eclipse CDT 8.2 and get started
C++ program with Makefile
- max.berger: Setting up Eclipse CDT on Windows, Linux/Unix, Mac OS X
- intel: Using Intel® C++ compiler with the Eclipse IDE on Linux
-
C/C++ development user guide
- eclipsesource: Shared libraries with Eclipse CDT and cygwin on Windows
- Linux, C++ and other Tortures: Shared libraries with Eclipse
- cudaverse: Eclipse with CUDA
- pourounas: Getting ready to develop with CUDA in Eclipse under Ubuntu
- skeelooslaboratory: Quickstart: CUDA using Bayreuth University CUDA toolchain for Eclipse
- opencv:
Using OpenCV with Eclipse (plugin CDT)
Include directory in Eclipse CDT:
- 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 - Location, location, location: Eclipse CDT and shared libraries
- google:
Shared libraries on Linux
The shared library won't be available at runtime even though the compiler found it at link time.
- stackoverflow: Eclipse CDT not generating symbols for new projects
- stackoverflow: “Export” button in Eclipse CDT “Paths and Symbols” dialog?
- askubuntu: How to make Eclipse CDT's Linux GCC toolchain resolve C++ standard library headers?
- codeproject: C++ Development using eclipse IDE– Starters guide
- stephanfr:
Debugging GCC in Eclipse CDT 4.2
I use the Web Upd8 PPA repository for Ubuntu to install the JDK.
- Gadgetron:
Linux CUDA setup
To set the path permanently, set the path in your startup file.
PATH=/usr/local/jdk1.7.0/bin:$PATH
For bash, edit the startup file (~/.bashrc):
export PATH
- qt-project:
Show library dependencies
Linux uses the “ldd” command to show the libraries that are linked to an executable or another shared library
- askubuntu: Dependency Walker for ubuntu
- stackoverflow: Dependency Walker equivalent for Linux?
- stackoverflow:
How to see full 'ldd' path details, instead of “file not found”?
find / -ls | grep libssl.so
- binarytides:
How to get information about graphics card (GPU) on Linux
lspci -vnn | grep VGA -A 12
- cyberciti:
Linux find out graphics card installed in my system
sudo apt-get install hardinfo
- cgl.ucsf:
Update Linux graphics driver
glxinfo | grep OpenGL
- superuser:
Need to find out the name of the graphics card and and if driver is installed?
lspci | grep VGA
lsmod | grep nv
- askubuntu:
How to install NVIDIA.run?
sudo ./NVIDIAxxxx.run --no-x-check
- howtogeek: Clean up the new Ubuntu Grub2 boot menu
- howtogeek: How to configure the Linux Grub2 boot menu the easy way
- askubuntu: How do I change the GRUB boot order?
- dedoimedo: GRUB 2 bootloader - Full tutorial