Libraries vs. Header files?

:-?

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

31 Replies - 6490 Views - Last Post: 22 December 2009 - 11:58 AM Rate Topic: ***** 1 Votes

#1 Sn0wm4n  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 08-July 08

Libraries vs. Header files?

Posted 21 December 2009 - 07:12 PM

Can someone please describe to me the difference between header files and shared libraries and static libraries and how they work together or what??? I tried reading about it but I can find anything that makes sense to me. Thanks
Is This A Good Question/Topic? 0
  • +

Replies To: Libraries vs. Header files?

#2 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5364
  • View blog
  • Posts: 27,325
  • Joined: 10-May 07

Re: Libraries vs. Header files?

Posted 21 December 2009 - 07:25 PM

I am under the impression that a header file (or shared library) gets compiled into your programs executable binary. Where as the linked library is just a link, & accesses (or remotely executes) from the dll, which is already (or at run time gets) loaded into memory.
Was This Post Helpful? 0
  • +
  • -

#3 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Libraries vs. Header files?

Posted 21 December 2009 - 07:27 PM

What have you read already?

Give us some idea of where you have already been so we don't just tell you the same stuff that didn't make sense the first time.
Was This Post Helpful? 0
  • +
  • -

#4 Sn0wm4n  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 08-July 08

Re: Libraries vs. Header files?

Posted 21 December 2009 - 07:30 PM

From what I have read, static libraries take the code form its header files and copy it into the program when compiled whereas dynamic library header files just copy ab address of an executable? that the executable should look for to find the proper executable code. But I'm not sure if that is even right and how they all tie together
Was This Post Helpful? 0
  • +
  • -

#5 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5364
  • View blog
  • Posts: 27,325
  • Joined: 10-May 07

Re: Libraries vs. Header files?

Posted 21 December 2009 - 07:31 PM

View PostSn0wm4n, on 21 Dec, 2009 - 08:30 PM, said:

But I'm not sure if that is even right and how they all tie together

They shouldn't tie together. They are two separate methods with two different conclusions.
Was This Post Helpful? 0
  • +
  • -

#6 Sn0wm4n  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 08-July 08

Re: Libraries vs. Header files?

Posted 21 December 2009 - 07:35 PM

I also don't understand why you would compile a library... I thought a library was just a set of pre-written functions.

@no2pencil
I understand that they aren't supposed to be linked. I meant between the 2 types of libraries and header files
Was This Post Helpful? 0
  • +
  • -

#7 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5364
  • View blog
  • Posts: 27,325
  • Joined: 10-May 07

Re: Libraries vs. Header files?

Posted 21 December 2009 - 07:41 PM

** Disclaimer ** I could be totally wrong here...

View PostSn0wm4n, on 21 Dec, 2009 - 08:35 PM, said:

I also don't understand why you would compile a library...

Say you wrote a bitchin' search algorithm, but it's huge in file size & in memory usage. You could compile it as a dll & then each program that runs it will share it's memory space. It won't exist in your executable binary, but will be required to have with it when it runs. So if you move it to another machine, it must exist there. Now, say you write a follow up project that uses this same code. You simply load the dll, & execute the function. However, if you put that code into a header file, & you have someone download product A, they are not going to recompile it. So therefore executable binary for project b must also be compiled with the bitchin' search algorithm directly in the binary executable.

Therefor, the dll is reusing code at execution time. The header file is reusing the code at compile time.
Was This Post Helpful? 0
  • +
  • -

#8 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Libraries vs. Header files?

Posted 21 December 2009 - 07:44 PM

View PostSn0wm4n, on 21 Dec, 2009 - 06:35 PM, said:

I also don't understand why you would compile a library... I thought a library was just a set of pre-written functions.


All C/C++ code needs to be compiled before it will work.
C/C++ are not a script languages that can be interpreted direct from the code as written.
C/C++ code must be compiled before the code will do anything on a computer.
Was This Post Helpful? 0
  • +
  • -

#9 Sn0wm4n  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 08-July 08

Re: Libraries vs. Header files?

Posted 21 December 2009 - 07:51 PM

I UNDERSTAND THAT... I just don't understand why you would pre-compile it before the actual program is compiled. What would be the point in that? Why wouldn't you just compile it all together at once?
Was This Post Helpful? 0
  • +
  • -

#10 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5364
  • View blog
  • Posts: 27,325
  • Joined: 10-May 07

Re: Libraries vs. Header files?

Posted 21 December 2009 - 07:57 PM

Because that's not how a DLL is designed to work.
Was This Post Helpful? 0
  • +
  • -

#11 Sn0wm4n  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 49
  • Joined: 08-July 08

Re: Libraries vs. Header files?

Posted 21 December 2009 - 08:02 PM

are things like iostream static libraries that just give you the source code and then put them in the program when you compile it? And something like blahblah.dll is a pre-compiled binary that a program looks for when it is asked to use a function from it? I just dont' get how you can use a dynamic library in a program since it is already compiled.
Was This Post Helpful? 0
  • +
  • -

#12 GenHornet18  Icon User is offline

  • Darken the Radar

Reputation: 36
  • View blog
  • Posts: 629
  • Joined: 19-October 09

Re: Libraries vs. Header files?

Posted 21 December 2009 - 08:03 PM

Well to your last question there, although I haven't used very many libraries myself because they can be a bitch to work with, I believe you would have to compile them first just as you would have to create a function prototype. The program needs to know it exists before it is used. If you check over at MSDN there are few articles about libraries and headers but there written in the usual difficult-to-read form.
Was This Post Helpful? 0
  • +
  • -

#13 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2874
  • View blog
  • Posts: 11,047
  • Joined: 15-July 08

Re: Libraries vs. Header files?

Posted 21 December 2009 - 08:05 PM

View PostSn0wm4n, on 21 Dec, 2009 - 08:51 PM, said:

I UNDERSTAND THAT... I just don't understand why you would pre-compile it before the actual program is compiled. What would be the point in that? Why wouldn't you just compile it all together at once?


Like No2Pencil said, you could compile a whole program together, but to make that module reusable between many different programs that all use that module, one would make it a DLL, so that it can be CALLED from the appropriate executable while still being available for others. Let's use SDL 2D game library as an example. Instead of compiling THE ENTIRE library into a single executable, you have it as separate DLLs which are used in that program. This also makes them great for when people update the executable; the end user does not have to recompile it, as it is already there set up as a DLL.

This post has been edited by Dogstopper: 21 December 2009 - 08:10 PM

Was This Post Helpful? 0
  • +
  • -

#14 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5364
  • View blog
  • Posts: 27,325
  • Joined: 10-May 07

Re: Libraries vs. Header files?

Posted 21 December 2009 - 08:09 PM

View PostSn0wm4n, on 21 Dec, 2009 - 09:02 PM, said:

I just dont' get how you can use a dynamic library in a program since it is already compiled.

As you learn more about programming & software development, you will.

I guess, you can think about it like this. When is the last time that you actually opened up the header file & looked at the source code for printf (or cout)?? You know it's parameters, & you know what output to expect, so you are able to call it, pass it values, & expect a return code from it without reading into every detail of it's code. The DLL will work in this way (as to a developers situation).
Was This Post Helpful? 0
  • +
  • -

#15 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Libraries vs. Header files?

Posted 21 December 2009 - 08:14 PM

Ahhh "pre-compile" that makes more sense.
Care in use of terms is important.
Nearly the same word can mean the exact opposite in IT so one must be careful to use exactly the term you mean.

1 - Read what No2Pencil has already said. Words of wisdom all.

2 - Have a read of these:
http://msdn.microsof...b00(VS.71).aspx
http://www.cygnus-so...ledheaders.html
http://en.wikipedia....compiled_header

As just one example:
If you have a Windows machine you can access the pre-compiled library Windows.h simply by including it in your code.
- Do you think Microsoft wants that sitting on your machine in code rather than compiled binary? You would see into their APIs in a way they don't want you to.
- You don't want all that code cluttering up your hard drive when all you need is the binary.
- If it is open code you (or someone else) might be tempted to fiddle. Suddenly all the work done by M$ to write and test that code is worth zero if any first year comp sci student can make "improvements" and thereby total their machine and spend hours on the phone to help asking why it broke.
- Do you really want to sit for extra seconds, maybe minutes, while huge libraries compile every time you want to knock up a "Hello World" (if you think you do I can assure you that you do not).
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3