LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-25-2013, 01:36 PM   #1
IneptCoder
LQ Newbie
 
Registered: Jun 2013
Location: my house
Distribution: centos, ubuntu
Posts: 10

Rep: Reputation: Disabled
Information on Libraries and Compilers


I am new to Linux (and working with computers in general) and I wanted to know more about the programming and libraries. Specifically, I wanted to know where the libraries are stored on the computer. Also, does the compiler come with libraries or does your compiler soley rely on the libraries stored on the computer (I am using GCC)? Also, I don't really understand the compiler process. From what I gather the compiler convertes the code you write into machine language (is that binary?) and it also "links" libraries (pre-compiled code?) and your different files together. I am not really sure how that linking works. So, it would be great if anyone has any good info they want to share or point me in the right direction.
 
Old 06-25-2013, 02:22 PM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
It all depends.

Libraries can be anywhere.

DEFAULT libraries are in one of (3?) places - /usr/lib64 (for 64 bit libraries), /usr/lib (32 bit libraries), /usr/local/lib ...

The /usr/local/lib is frequently used to to hold site (your site) specific application/libraries, hence the /usr/local directory tree usually includes a bin, etc, lib...

Some development libraries are not always installed. The normally installed libraries are shared libraries - meaning that only one memory resident version exists, but are mapped into many processes memory range. Development libraries are usually named xxx.a, meaning "archive". Sometimes these libraries include debugging modules, as well as including debugging symbols. Both can be useful during development.

It is up to the distribution to decide how to package such things. frequently the compiler will only include the base runtime libraries (the .a) because there are so MANY different libraries (X has a couple of dozen, then there are more for C++, Fortran, GUI toolkits...)

The compiler proper only translates from the source code to a ".o" file (meaning "object"). A separate linker will combine these together (usually, the link phase is automatically done for simple programs). Libraries are created using a different utility (ar - for "archiver"). Shared libraries are created by the linker (ld - for "link edit") by giving it specific options.

Nearly all compilers have multiple passes/phases:

1. preprocessor - scan the file creating/expanding macros, adding definitions (prototypes) for library functions. The output is then passed to
2. the scanner/tokenizer/compiler (may be all one unit). The output of this is usually passed to
3. an optimizer which tries to optimize speed/memory usage which sometimes outputs to a
4. code generator that generates the final object file.

If it is a relatively simple (or at the end of a long series of compiles) the compiler can then invoke a linker that combines all the listed object files, libraries referenced (or implied - gcc assumes you are going to use libc, so normally you don't have to give that one)
 
1 members found this post helpful.
Old 06-25-2013, 02:43 PM   #3
IneptCoder
LQ Newbie
 
Registered: Jun 2013
Location: my house
Distribution: centos, ubuntu
Posts: 10

Original Poster
Rep: Reputation: Disabled
Thank you for the information.
So in C++ do you "#include <somelibrary>",because "somelibrary" is a library that is not already included by the compiler?
 
Old 06-25-2013, 03:14 PM   #4
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
yes and no
you don't 'include' libraries, you include HEADERS, which are re-usable parts of other parts of programs, such as libraries, that allow developers to interact with said programs/libraries at a programming level, or to perform tasks without 'reinventing the wheel', such as stdio.h
http://en.wikipedia.org/wiki/Header_file

and in answer to your second query, nothing is 'included' by the compiler by default, any header you need must be explicitly included.
 
1 members found this post helpful.
Old 06-25-2013, 04:04 PM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
A #include causes the referenced file to be read as input to the compiler.

"include files" have definitions (macros, structures, enumeration,...), some for constants (such as flag values), some for function prototypes so that the compiler can verify parameter types.

A compiler command such as "gcc" can invoke the linker with standard libraries (gcc uses "libc"). All other libraries have to be referenced so that the linker can use the appropriate ones.

To this end, there are a lot of tools available (autoconf, make, ar, various editors - especially emacs which has a lot of IDE like attributes).
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to find the version information of installed libraries say for example libdec2.a atulspma AIX 6 05-31-2017 07:32 PM
Find out the version information of installed libraries on AIX atulspma AIX 0 04-06-2009 02:22 AM
no version information available, replaced libraries Peterius Debian 3 11-12-2008 01:47 AM
FREE Compilers and Cross-Compilers for LINUX and WINDOWS. Bernstein34 Linux - Software 1 05-05-2008 12:54 PM
What compilers/ libraries ect do I need installed so that I can compile most software jimdaworm Linux - Newbie 2 09-12-2003 03:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration