4 Replies - 964 Views - Last Post: 21 January 2011 - 03:01 PM

#1 heyoman1  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 64
  • View blog
  • Posts: 735
  • Joined: 30-November 09

What is a lib/dll?

Posted 20 January 2011 - 06:49 PM

I always put them in my project folders because they required them, but I never knew for what purpose. What is a .lib and .dll file? I know that .dll is Windows specific, so is a .lib cross platform?

This post has been edited by heyoman1: 20 January 2011 - 07:18 PM

Is This A Good Question/Topic? 0
  • +

Replies To: What is a lib/dll?

#2 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: What is a lib/dll?

Posted 20 January 2011 - 08:20 PM

Quote

so is a .lib cross platform?
No, it is compiler specific. Actually, more than that. It can be compiler setting specific, etc.. So there's no guarantee of lib files being portable at all.

A dll file (at least the type you care about) is a binary target like any executable program. However, a DLL is not something directly executable. It has compiled code that can be loaded by a program and then run. There are Windows API functions to deal with this loading portion.

A lib file is a compiler specific artifact. Each source file is compiled to an object file. One thing you can do is link all object files together to create an end binary like a DLL or an executable.

However, you can also create essentially a compiler specific package. This is just an archive of compiled files, a static library, that you can then use later on. You can then link in this archive with more object files to create a binary. For example, let's say you wrote a math library. You have 20 source files that take a couple of minutes to compile. Instead of compiling them over and over and over, you can compile them once into a static library. Then, for any programs that rely on this library, you can just link the library in. You still need headers during the compilation process, but during link time, you provide the library instead of object files.

One confusing aspect is import libraries. I said earlier that DLLs need to be loaded, etc. Your compiler probably creates a bit of code to do this automatically. This is presented to you as a lib file. So if any program wants to make use of a DLL, it just links to the lib file. Without the lib file, the program would have to be programmed to manually load the library file.
Was This Post Helpful? 2
  • +
  • -

#3 heyoman1  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 64
  • View blog
  • Posts: 735
  • Joined: 30-November 09

Re: What is a lib/dll?

Posted 20 January 2011 - 08:43 PM

You say a lib is compiler specific. What if I developed a product want wanted to distribute it, and potentially to other OS's. Would I have to create different libs for each platform?
Was This Post Helpful? 0
  • +
  • -

#4 lordofduct  Icon User is online

  • I'm a cheeseburger
  • member icon


Reputation: 2533
  • View blog
  • Posts: 4,633
  • Joined: 24-September 10

Re: What is a lib/dll?

Posted 21 January 2011 - 08:36 AM

.dll - on windows is a 'dynamic link library'

.lib - on windows is a 'static library'

dll's are included with the installed package as separate files because they are dynamic. Meaning they can be changed out. You can replace the .dll, or add .dll files and the main executable will automatically be updated with new/patched code.

static libraries on the other hand are static. They don't change. The static library is usually compiled into the executable, so that the executable holds all the code in it. Hence why it's static, it can't be swapped out. This means it is only needed at compile time, once compiled you don't need to distribute it... it's like the source files, useful for coding, unnecessary for distributing (unless you're distributing the source code as well).



As for cross-platformability... that's on a library to library basis. If you have some static library that is specific to accessing window's directories... well then obviously you can't compile it for linux or mac.
Was This Post Helpful? 0
  • +
  • -

#5 heyoman1  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 64
  • View blog
  • Posts: 735
  • Joined: 30-November 09

Re: What is a lib/dll?

Posted 21 January 2011 - 03:01 PM

What about .a files? Aren't they another form of a library? I had to link to them when I used to use Allegro on Dev-C++.

This post has been edited by heyoman1: 21 January 2011 - 03:04 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1