Prev: SIGPIPE doesn't work in Cygwin?
Next: where is good sample code I can learn about linux system programming
From: carl on 19 May 2010 16:18 In a program I include the file zlib.h. When I include that file I suddenly needs to specify a library file which it should "link against". Why does some .h files need a library file and what does it mean that it links against the library file?
From: David Schwartz on 19 May 2010 17:04 On May 19, 1:18 pm, "carl" <carl@.com> wrote: > In a program I include the file zlib.h. When I include that file I suddenly > needs to specify a library file which it should "link against". Why does > some .h files need a library file and what does it mean that it links > against the library file? In most platforms you are likely to use, when you include zlib.h, it literally includes everything in the zlib.h as if you had typed it into your program. So anything you could do in the program can be done in the header file. DS
From: carl on 19 May 2010 17:18 "David Schwartz" <davids(a)webmaster.com> wrote in message news:7a831dd7-d544-427f-801b-2396a1361cad(a)j36g2000prj.googlegroups.com... On May 19, 1:18 pm, "carl" <carl@.com> wrote: > In a program I include the file zlib.h. When I include that file I > suddenly > needs to specify a library file which it should "link against". Why does > some .h files need a library file and what does it mean that it links > against the library file? In most platforms you are likely to use, when you include zlib.h, it literally includes everything in the zlib.h as if you had typed it into your program. So anything you could do in the program can be done in the header file. DS But what is the difference between including a file and linking against a file?
From: John Gordon on 19 May 2010 17:24 In <4bf447b7$0$281$14726298(a)news.sunsite.dk> "carl" <carl@.com> writes: > In a program I include the file zlib.h. When I include that file I suddenly "Suddenly" implies that this was not happening before you included the .h file. Is this correct? After adding the statement #include <zlib.h>, your program suddenly stops compiling? > needs to specify a library file which it should "link against". Why does What is telling you that you "need to specify a library file"? Is it your compiler? Please post the exact error message that you're seeing. > some .h files need a library file and what does it mean that it links > against the library file? It means that while the .h file contains stuff like function prototypes, the actual *code* for those functions is in the library. Think of it like a manual for a washing machine. The manual tells you how to use the machine, what to expect during operation, how to fill it with soap, etc. But if you want to actually wash clothes, the manual alone isn't enough. You still need the machine itself to do the work. -- John Gordon A is for Amy, who fell down the stairs gordon(a)panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies"
From: Moi on 19 May 2010 18:03 On Wed, 19 May 2010 23:18:23 +0200, carl wrote: > "David Schwartz" <davids(a)webmaster.com> wrote in message > news:7a831dd7-d544-427f-801b-2396a1361cad(a)j36g2000prj.googlegroups.com... > On May 19, 1:18 pm, "carl" <carl@.com> wrote: >> In a program I include the file zlib.h. When I include that file I >> suddenly >> needs to specify a library file which it should "link against". Why >> does some .h files need a library file and what does it mean that it >> links against the library file? > > In most platforms you are likely to use, when you include zlib.h, it > literally includes everything in the zlib.h as if you had typed it into > your program. So anything you could do in the program can be done in the > header file. > > DS > > But what is the difference between including a file and linking against > a file? A small experiment. The following code compiles and links even though zlib.o is not linked in. ::: #include <zlib.h> int main(void) { return 0; } Why is this ? Because no function from zlib is actually *referenced* by this tiny program. The header file just mentions to the compiler that they exist. And if an *actual* reference would be made, it can be compared to the declarations / prototypes / et cetera. HTH, AvK
|
Next
|
Last
Pages: 1 2 3 4 Prev: SIGPIPE doesn't work in Cygwin? Next: where is good sample code I can learn about linux system programming |