Sign in to follow this  
v0dKA

Setting up a library in Linux

Recommended Posts

Hello, I very recently installed Linux, and I'm trying to do some programming on it. I downloaded a library called libwww from here: http://www.w3.org/Library/Distribution.html. The file came in a .tgz file, which brings up a file extracting program when opened. My question is this: in Linux, where are libraries customarily unpacked? And how can I get by the access restrictions? (I am not provided with a password prompt from the graphical Extract program. Should I unpack it from the command line then? Using what?) Thanks in advance for the help.

Share this post


Link to post
Share on other sites
the .tgz extension means the file is a gzip compressed tarball. for more info, please look at 'man gzip' and 'man tar' (these commands should be run from a command line prompt)

from the content of the archive, i can see this is a source distribution library, which means you need to compile the library in order to use it. It also contains a configure script which is common on unix/linux.

to install it, simply run (from the uncompressed archive directory)

./configure --prefix=/usr
make
makeinstall

to explain a little bit better, the ./configure commands execute the configure script _in the current directory_ (hence the ./). the --prefix=/usr option is to tell the configure script we want to install the library to /usr/lib instead of the common location /usr/local/lib. it's not mandatory, but i found things easier when installed there. after the script execute you should have a Makefile file created in the current directory, if not, there have been an error in the script (read what it says and try to find what's missing).

the make command will execute the Makefile file and compile each .c files for the library and make a .a or .so file out of it (the actual library: .a is for static libs and .so is for shared object (equivalent to windows .dll)

the make install command will execute the 'install' section from the Makefile which installs the library. it will copy a bunch of files to some locations. this commands _must_ be run as root (or you wont have write access to the directories where the library will be installed).

what i've discribed here is the common process to install softwares/library that uses the autoconf, automake packages to build itself. in order to be able to build the library you'll need the GNU Compilers Collection (gcc) and the -devel packages of every dependencies the thing you want to build needs.

i don't know which distribution you use, but the commons installers for these -devel packages and gcc are
rpm on redhat linux (yum on fedora core)
yast on suse linux (or opensuse)
and installdrake (if i remember correctly) on mandrake (now known as mandriva)

also remember that you can always look at the man pages of almost every commands you can type on linux using the 'man' command (some distributions also include a graphical software to do this) and there's also The Linux Documentation Project which can help you !

hope that helps !

--edit--
If anybody find errors in what i have written feel free to say it because i don't have that much experience with linux and don't want to induce people in error

--edit2--
after more checking of the archive content, you can also read the README.html and INSTALL.html files inside the archive which will help you with specific options to this package

Share this post


Link to post
Share on other sites
Well, if it's in a .tgz file (commonly called "tarballs") it may contain source. You should probably do this from a command-line... it's much easier in linux to work with these sorts of things from the shell.

Go to the directory where you downloaded the .tgz file (let's call it myfile.tgz). When you are in the directory, type:
tar -xzf myfile.tgz

This should decompress everything. Just so you know, the tar utility "sticks" files together. gzip zips them. If you tar a bunch of files, then gzip them, you have a tarball. Sometimes they are named like myfile.tar.gz. The -z option above tells tar to run everything through gunzip when it untars.

Once you have done that, the tarball should have extracted to a subdirectory called myfile. (This is fairly standard... tarballs typically contain a top level directory so that they extract cleanly and play nice).

Now, you may have source code in the subdirectory. You will probably need to get in there and execute these commands:
./configure
./make
./make install


This will configure, compile, then install whatever it was you downloaded. And to answer your question... when you install libs in linux, they typically go all over the place. The libs themselves (whatever.so and other variants) usually go to /usr/lib or /lib. The documentation will probably go somewhere under /usr/share/. Icons may go under /usr/share/icons/ or something like that.

There is no firm answer, but there are some fairly standard places where things are put. I suggest installing (assuming you don't have it) the locate utils. You can occasionally run
updatedb
as root, and then you can easily find files by using
locate filename
(filename can be a regex, actually).

What distro are you using? It probably has some package management system, which might make it much easier to get your libs installed.

(EDIT: He beat me... :-( )

TO ADD A COUPLE OF THINGS:

If you are using Ubuntu or another variant of Debian, you can use apt to get packages easily...

Let's say your looking for gcc. First, make sure your apt cache is up to date... if you haven't updated it recently, type:
apt-get update

This updates the apt-cache with packages from all of the repositories you have listed. Then, to search for all available packages with gcc in the title or description, type:
apt-cache search gcc

This will list a lot of packages that contain the gcc keyword. Find the one you want, then download and install it automatically by typing:
apt-get install packagename

Sometimes these package names have versions and other stuff in them. It's that easy. APT will manage all of your packages for you and resolve any dependencies (which is a real pain in the ass to do yourself, sometimes at least).

If you don't have Ubuntu or debian variant, your distro probably has something similar. As the previous poster mentioned, Redhat has yum, and other distros have their own flavor of package management.

Share this post


Link to post
Share on other sites
if the updatedb or locate programs aren't installed on you system, you can always use the find command which comes from the findutils package and is usually installed by almost every distribution

find <directory to search> -name <name of file>

so if you're on the / directory and wants to find the the_file file then you'd do
find . -name the_file

Share this post


Link to post
Share on other sites
Thank you very much for the detailed explanations.

A little question about searching for libraries: does the "apt-get search" command search some sort of a specialized repository of packages approved for Linux? Or just the web? I'm asking because I cannot find the aforementioned library "libwww" by using apt-get search. I get similar items for other languages, but none for C/C++:

Quote:

$ apt-cache search libwww
devscripts - Scripts to make the life of a Debian Package maintainer easier
libhtml-parser-perl - A collection of modules that parse HTML text documents
libhtml-tree-perl - represent and create HTML syntax trees
liburi-perl - Manipulates and accesses URI strings
libwww-perl - WWW client/server library for Perl (aka LWP)
python-clientform - module for handling HTML forms on the client side
python2.4-clientform - module for handling HTML forms on the client side


Anyways, I successfully installed my first Linux library [smile]. Thanks for the help!

Share this post


Link to post
Share on other sites
Ok, there is another fairly standard directory called /etc. This directory has configuration type stuff in it. There should be a directory in there, /etc/apt, which contains a file called sources.list. This is the file that contains all of your repositories... you can track down more of them (google "ubuntu apt repositories", or whatever you are using [EDITED: see bottom of post]) and put them here, just make sure to run "apt-get update" afterward to update the cache.

THIS NEXT BIT MIGHT SAVE YOU A LOT OF TIME IF YOU USE UBUNTU (or even if you don't):

If you are using ubuntu, though, you should already have Synaptic installed (should be under some system or administration menu somewhere)--Synaptic isn't specific to Ubuntu, but Ubuntu comes with it for sure. Synaptic is a GUI front-end for APT, and makes things a little nicer to work with for some people. Go into Synaptic, and there should be a menu on the top that contains a Repositories menu item (something like that, you can find it). When you go into that Repositories setup screen, tell it to add a new repository. If I recall correctly, it will default to some official ubuntu repos that you can check or uncheck. You want to check universe and multiverse, which should give you immediate access to something like 18000 packages.

You can usually get away with adding the debian repositories also, but make sure you need to do that before you do it.

If you are using ubuntu (sorry to keep saying that, but you never said), then here is a quick little guide to adding repositories manually (among many, many other useful things you might like to know). If includes a new sources.list that you can just copy over yours to enable some extra stuff.

Oh, and there is also this source-o-matic site that will generate a GIGANORMOUS sources.list for you, but be careful... just select what you absolutely need or it can put so much stuff in there that it could cause some conflicts down the road.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this