Page 1 of 1
Difference between an API and Library
Posted: Mon Sep 28, 2009 10:05 am
by Pennywise
Hi everyone.
I was just wondering what the difference between an API and a library was.
I hear that OpenGL is a Library and an API and I was wondering what the difference was.
Thanks
Re: Difference between an API and Library
Posted: Mon Sep 28, 2009 10:47 am
by K-Bal
It is more like a library has a API (application programming interface). The API is your access point to the library.
Re: Difference between an API and Library
Posted: Mon Sep 28, 2009 11:30 am
by Pennywise
So a library has an API.
Is it like how C++ has a compiler(GUI - Graphical User Interface) or different?
Re: Difference between an API and Library
Posted: Mon Sep 28, 2009 11:48 am
by K-Bal
A GUI is not part of a compiler. You are talking about an IDE, however, it's not comparable.
Why don't you just do a websearch?
http://en.wikipedia.org/wiki/Applicatio ... _interface
Re: Difference between an API and Library
Posted: Mon Sep 28, 2009 12:10 pm
by Pennywise
Yep, I did a few times but did not quite understand it. ^^
Re: Difference between an API and Library
Posted: Mon Sep 28, 2009 10:39 pm
by MarauderIIC
Think of it this way.
You have a car. The car is the library.
The car has a door, steering wheel and gas pedal. This is the API.
At least, that's what I get from what K-Bal said. I'm not quite sure myself =)
Re: Difference between an API and Library
Posted: Mon Sep 28, 2009 11:15 pm
by Falco Girgis
An API offers a level of abstraction between you and something. A library can or cannot have/be an API, but pretty much always an API will be a (or in a) library.
Think about something like OpenGL. It offers a level of abstraction between you (the programmer) and the video hardware, by giving you things like hardware accelerated rendering. OpenGL is an API. It is also a library.
Look at SDL. It is a library, but it is also a collection of APIs. It has a video API that gives you 2D blitting, an audio API that allows you to play sound and music, then timer, networking, and input--these all offer levels of abstraction between hardware and the programmer.
The Lua library has an API that allows the programmer to interact with Lua (states) at a higher level.
A library is simply a group of functions (and/or classes) compiled as a .lib (or .dll) that your program can statically (or dynamically) link to. When you use cout and printf, they're available because you're linking to the C and C++ standard libraries. These functions aren't considered APIs, because they aren't offering a layer of abstraction between you and something.
Re: Difference between an API and Library
Posted: Tue Sep 29, 2009 6:05 am
by K-Bal
GyroVorbis wrote:These functions aren't considered APIs, because they aren't offering a layer of abstraction between you and something.
Although it would be harder to write a text pixel per pixel in the framebuffer
Re: Difference between an API and Library
Posted: Tue Sep 29, 2009 2:27 pm
by dandymcgee
K-Bal wrote:GyroVorbis wrote:These functions aren't considered APIs, because they aren't offering a layer of abstraction between you and something.
Although it would be harder to write a text pixel per pixel in the framebuffer
Trust me, it is.
Re: Difference between an API and Library
Posted: Wed Sep 30, 2009 4:41 am
by Pennywise
I been looking it up better and found this out:
API (Application Programming Interface)
Refers to how you interact with the library. A good API makes it very easy to code with the library. Usually when people say they prefer Direct 3D or OpenGL they are talking about the API.
Library
Other code that someone has written so you don't have to. Your code uses the library to perform tasks that might be impossible otherwise (Windowing, Networking, fast 3D graphics) or might just take a lot of code that you don't want to write (compression, image loading, XML parsing)
I found this on gpwiki.org.
I get it now. Thanks for your help ^^
Re: Difference between an API and Library
Posted: Thu Oct 01, 2009 5:33 am
by Pennywise
One more question:
Can someone recommend me what scripting language I should learn please
Thanks
Re: Difference between an API and Library
Posted: Thu Oct 01, 2009 6:05 am
by K-Bal
Pennywise wrote:One more question:
Can someone recommend me what scripting language I should learn please
Thanks
Don't bother implementing scripting functionality in your program until you are really firm in your primary language and complete some projects.
Re: Difference between an API and Library
Posted: Fri Oct 02, 2009 2:52 am
by Pennywise
Oh God No
I was just asking for future reference