1 / 7

Linux Libraries

Linux Libraries. Jim Fawcett CSE775 – Distributed Objects Spring 2012. Conventions. Libraries that are loaded into an executable at run-time are called: Dynamic Link Libraries (Windows) Shared Libraries (Unix and Linux) Libraries that are bound at compile-time are called:

harken
Download Presentation

Linux Libraries

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Linux Libraries Jim Fawcett CSE775 – Distributed Objects Spring 2012

  2. Conventions • Libraries that are loaded into an executable at run-time are called: • Dynamic Link Libraries (Windows) • Shared Libraries (Unix and Linux) • Libraries that are bound at compile-time are called: • Static Libraries (both Linux and Windows)

  3. Static Libraries • Static libraries are created with the ar tool: • ar options archive object-file, … • ar r libdemo.a file1.o file2.o file3.o • Naming convention: • lib<name>.a • Some options: • r replace or insert • d delete • t show contents • v verbose

  4. Static Libraries • Create example: • g++ -c file1.cpp file2.cpp file3.cpp • ar r libdemo.a file1.o file2.o file3.o • rm file1.o file2.o file3.o • Using library • g++ -c main.cpp • g++ -o main main.olibdemo.a • Alternate use when library is in standard place like /usr/lib • g++ -o main main.o -ldemo

  5. Shared Libraries • Shared libraries are created with g++: • g++ -shared –o lib<name>.so file1.o … • Naming convention: • lib<name>.so • Object files must be position independent code: • g++ -c -fPIC -Wall file1.cpp …

  6. Shared Library • Creating shared library: • g++ -c -fPIC -Wall file1.cpp file2.cpp file3.cpp • g++ -shared –o libdemshare.so file1.o file2.o file3.o • Using a shared library: • g++ -Wall –o main main.cpp libdemshare.so • LD_LIBRARY_PATH=. (lib in current directory) • ./main

  7. Installing Libraries • Standard library search path: • /usr/lib • Set environment on startup • Put this definition in .profile • LD_LIBRARY_PATH=<your library path>

More Related