Difference between an API and Library

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
Pennywise
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 55
Joined: Tue Sep 22, 2009 1:36 pm
Favorite Gaming Platforms: Megadrive(Genesis), Dreamcast, SNES, Nintendo 64
Programming Language of Choice: C, C++ and Java
Location: England

Difference between an API and Library

Post 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
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: Difference between an API and Library

Post by K-Bal »

It is more like a library has a API (application programming interface). The API is your access point to the library.
User avatar
Pennywise
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 55
Joined: Tue Sep 22, 2009 1:36 pm
Favorite Gaming Platforms: Megadrive(Genesis), Dreamcast, SNES, Nintendo 64
Programming Language of Choice: C, C++ and Java
Location: England

Re: Difference between an API and Library

Post by Pennywise »

So a library has an API.
Is it like how C++ has a compiler(GUI - Graphical User Interface) or different?
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: Difference between an API and Library

Post 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
User avatar
Pennywise
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 55
Joined: Tue Sep 22, 2009 1:36 pm
Favorite Gaming Platforms: Megadrive(Genesis), Dreamcast, SNES, Nintendo 64
Programming Language of Choice: C, C++ and Java
Location: England

Re: Difference between an API and Library

Post by Pennywise »

Yep, I did a few times but did not quite understand it. ^^
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: Difference between an API and Library

Post 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 =)
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: Difference between an API and Library

Post 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.
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: Difference between an API and Library

Post 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 ;)
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Difference between an API and Library

Post 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. :shock:
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
Pennywise
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 55
Joined: Tue Sep 22, 2009 1:36 pm
Favorite Gaming Platforms: Megadrive(Genesis), Dreamcast, SNES, Nintendo 64
Programming Language of Choice: C, C++ and Java
Location: England

Re: Difference between an API and Library

Post 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 ^^
User avatar
Pennywise
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 55
Joined: Tue Sep 22, 2009 1:36 pm
Favorite Gaming Platforms: Megadrive(Genesis), Dreamcast, SNES, Nintendo 64
Programming Language of Choice: C, C++ and Java
Location: England

Re: Difference between an API and Library

Post by Pennywise »

One more question:
Can someone recommend me what scripting language I should learn please :mrgreen:
Thanks
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: Difference between an API and Library

Post by K-Bal »

Pennywise wrote:One more question:
Can someone recommend me what scripting language I should learn please :mrgreen:
Thanks
Don't bother implementing scripting functionality in your program until you are really firm in your primary language and complete some projects.
User avatar
Pennywise
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 55
Joined: Tue Sep 22, 2009 1:36 pm
Favorite Gaming Platforms: Megadrive(Genesis), Dreamcast, SNES, Nintendo 64
Programming Language of Choice: C, C++ and Java
Location: England

Re: Difference between an API and Library

Post by Pennywise »

Oh God No :mrgreen:
I was just asking for future reference
Post Reply