Sign in to follow this  
EmperorXYZ

[C++ VS2010] Newb question about headers and libraries

Recommended Posts

EmperorXYZ    100
Hi, I've gone through college in computer engineering without knowing this, so I'd like to ask this now once and for all to end my shameful ignorance. I understand the concept of using libraries so that we don't have to reinvent the wheel and use code that has been well written and tested. I don't really understand it when in visual c++ 2010, you go in project properties linker input additional dependencies and add some .lib files for example d3d9.lib or alld.lib. I mean I suppose that's like adding libraries right? In that case, how come some times, I just need to #include <windows.h> and other times I need both #include <d3d9.h> and d3d9.lib.

Could someone please link me to a good article explaining this well? I'd like to understand it before I start learning about dynamic libraries. Thanks

Share this post


Link to post
Share on other sites
Texus    248
I know it is not really an answer to your question, but I wanted to say two things about it.

- I am not sure, but isn't the d3d9.lib enough? Do you actually need the header too?

- You may already know, but instead of changing your project properties you can just add the library with the following line in your code:
[code]
#pragma comment (lib, "d3d9.lib")
[/code]

Share this post


Link to post
Share on other sites
the_edd    2109
When you use the functionality of e.g. Direct-X where does that functionality come from? There has to be some "executable stuff" somewhere that a given program can take advantage of.

Quite often, as you point out, you have to tell the linker about this "executable stuff" (.lib files and so on) so that it can be linked in to your binary at the appropriate time.

However, each toolchain will link certain libraries automatically. For example the C runtime library is typically linked automatically, so you don't need to do anything special when calling printf(), other than #include <stdio.h> in order to tell the compiler about the function's interface.

kernel32 is also linked automatically on Windows (at least Visual C++ does this anyway), so some of the functionality advertised by <windows.h> requires no special action. But not all of it, so other libraries may need to be provided to the linker.

Share this post


Link to post
Share on other sites
EmperorXYZ    100
Not sure about the header. Will try next time without. Thanks for the #pragma comment line. I didn't know. Will be using that instead.

I see edd. That's fairly clear. I think it was really <windows.h> that threw me off because I was expecting a windows.lib file.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this