Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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)
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?
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233
Rep:
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.
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).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.