C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

why link against a library?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
happyvalley
Guest





PostPosted: Tue Jun 13, 2006 9:10 am    Post subject: why link against a library? Reply with quote



a silly question.

when linking a program,
the path to include files and library files are given already (-I, -L),
why still need to give the names of some library by -l , say -lm for
math library. otherwise, will get no reference error

thanks
Back to top
Dirk Feytons
Guest





PostPosted: Tue Jun 13, 2006 9:10 am    Post subject: Re: why link against a library? Reply with quote



happyvalley wrote:
Quote:
a silly question.

when linking a program,
the path to include files and library files are given already (-I, -L),
why still need to give the names of some library by -l , say -lm for
math library. otherwise, will get no reference error

-I and -L specify directories where respectively header files and
libraries can be found. They are different things so they don't
necessarily live in the same place. On a typical Linux system for
instance header files can be found in /usr/include while libraries are
in /lib.
The -l switch tells the linker which specific libraries to link against.
Just like you used #include to tell which header files to use for
compilation of a translation unit.
Header files typically only hold declarations. It just tells what
certain structures look like and which functions exist somewhere so the
compiler knows how to compile a translation unit. After that you still
need the actual code of those functions to create a working program.

See also
http://groups.google.com/group/comp.lang.c++/browse_frm/thread/3274db962f1f060c/8e616babfa4cbc97?lnk=st&q=linking+author%3Akarl+author%3Aheinz&rnum=1&hl=en#8e616babfa4cbc97



--
Dirk

(PGP keyID: 0x448BC5DD - http://www.gnupg.org - http://www.pgp.com)
Back to top
Jack Klein
Guest





PostPosted: Tue Jun 13, 2006 9:10 am    Post subject: Re: why link against a library? Reply with quote



On 12 Jun 2006 21:57:56 -0700, "happyvalley"
<nittanymountain (AT) gmail (DOT) com> wrote in comp.lang.c++:

Quote:
a silly question.

when linking a program,
the path to include files and library files are given already (-I, -L),
why still need to give the names of some library by -l , say -lm for
math library. otherwise, will get no reference error

thanks

Note that linkers and their operation are not really topical here,
since they are not defined by the language, and differ from one
compilers to another.

But in general, the path or set of paths that you specify to the
linker to search for libraries might contain dozens or hundreds of
them. A linker could be designed to search every single one of them
to see if it contains anything it needs, but there are two problems
with that approach.

The first is that it could make building an executable take much
longer.

The second is that a symbol could be defined in more than one library,
leading either to multiple definitions, or an executable that builds
without error but uses the wrong function or object.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
Back to top
Marco Wahl
Guest





PostPosted: Tue Jun 13, 2006 9:10 am    Post subject: Re: why link against a library? Reply with quote

a silly question.
Quote:

when linking a program,
the path to include files and library files are given already (-I, -L),
why still need to give the names of some library by -l , say -lm for
math library. otherwise, will get no reference error

This is merely a platform question than a C++ question.

In typical compile-link tools '-I' is used to specify
an include path, '-L' the path where to find libraries
and '-l' the name of the library. So all three are useful.


HTH
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.