Jump to content
  • Advertisement
Sign in to follow this  
sheep19

#including custom headers in VC++ 08

This topic is 3536 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I created a Sprite class to help me with my games. It uses SDL. I have some questions. To make a header available in this form #include <myheader.h> I have to create a lib file. I know that process. Now, I'm having some trouble doing this with my Sprite class. SDL uses dlls, so does this mean that I have to output a dll and not a lib file? Also, in the project that I will create the dll (or lib?), I have to include SDL.lib etc in linker-input right? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by sheep19
To make a header available in this form #include <myheader.h> I have to create a lib file. I know that process.
No you don't, you just have to add the directory that myheader.h lives in to your include path. It doesn't matter if it's a lib or not.

Quote:
Now, I'm having some trouble doing this with my Sprite class. SDL uses dlls, so does this mean that I have to output a dll and not a lib file? Also, in the project that I will create the dll (or lib?), I have to include SDL.lib etc in linker-input right?
You can create a static library (a .lib or .a) and dynamically link it to a dynamic library (a .dll or .dylib). So if you're using the SDL dll, but you're creating a static library, you can just link your static library to the SDL dll. You don't have to turn your static library into a dynamic library.

Share this post


Link to post
Share on other sites
Quote:
Original post by MikeTacular
You can create a static library (a .lib or .a) and dynamically link it to a dynamic library (a .dll or .dylib). So if you're using the SDL dll, but you're creating a static library, you can just link your static library to the SDL dll. You don't have to turn your static library into a dynamic library.


I meant being able to use it without including it in the header,like including <string> for example.

Share this post


Link to post
Share on other sites
Quote:
Original post by sheep19
Quote:
Original post by MikeTacular
You can create a static library (a .lib or .a) and dynamically link it to a dynamic library (a .dll or .dylib). So if you're using the SDL dll, but you're creating a static library, you can just link your static library to the SDL dll. You don't have to turn your static library into a dynamic library.


I meant being able to use it without including it in the header,like including <string> for example.


You mean you don't want to include the SDL headers in your own header file because that would force any users of your header file to also include the SDL headers? The only way I know of is the pimpl idiom, but of course if you expose any SDL features in your interface you'll have to include the SDL headers, so the pimpl idiom can only help if you are totally hiding your usage of SDL.

Share this post


Link to post
Share on other sites
Quote:
Original post by MikeTacular
Quote:
Original post by sheep19
Quote:
Original post by MikeTacular
You can create a static library (a .lib or .a) and dynamically link it to a dynamic library (a .dll or .dylib). So if you're using the SDL dll, but you're creating a static library, you can just link your static library to the SDL dll. You don't have to turn your static library into a dynamic library.


I meant being able to use it without including it in the header,like including <string> for example.


You mean you don't want to include the SDL headers in your own header file because that would force any users of your header file to also include the SDL headers? The only way I know of is the pimpl idiom, but of course if you expose any SDL features in your interface you'll have to include the SDL headers, so the pimpl idiom can only help if you are totally hiding your usage of SDL.


No,sorry for not explaining.

The compiler has directories for headers, source files and library files. I want to be able to put my headers in those directories and just #include <myheader.h> (using <> not ""). So in order to do this I have to create a lib file. My question was, because SDL is a dynamic library (dll), if I have to create a dll as well (because my sprite header file includes SDL.h) and not lib file.

Share this post


Link to post
Share on other sites
Quote:

The compiler has directories for headers, source files and library files.

Mostly correct. It has a list of paths/directories that it searches for those files based on platform and such. It typically does not "search" for source files, not using the same mechanism.

Quote:

I want to be able to put my headers in those directories and just #include <myheader.h> (using <> not "").

This is generally extremely poor practice and potential dangerous. Better to put your header in some directory of your own choosing and add that directory to the compiler's search paths. That gives you the behavior you want (being able to use the angle-bracket form of #include) in the correct manner, without doing evil, dangerous things to the compiler's mostly-private directories.

Quote:

So in order to do this I have to create a lib file.

This is not true. You do not need to create a library file just to put a header in a common location. It's acceptable to want to, and often useful, but it is incorrect to assert that you must.

Quote:

My question was, because SDL is a dynamic library (dll), if I have to create a dll as well (because my sprite header file includes SDL.h) and not lib file.

You do not. As long as the appropriate symbols are available at link time, your program will link. This is also why you do not need to create a static library to place your header someplace else.

Share this post


Link to post
Share on other sites
Quote:
Original post by sheep19
The compiler has directories for headers, source files and library files. I want to be able to put my headers in those directories and just #include <myheader.h> (using <> not ""). So in order to do this I have to create a lib file.

Using <> for your includes has nothing to do with whether or not you use a .lib file. To use <> for your includes, just put the directory that your header files are in on the include search path. In recent versions of MSVC you could do this by going to Tools->Options->Projects and Solutions->VC++ Directories and add the directory to the include path.

Share this post


Link to post
Share on other sites
Quote:
Original post by sheep19
No,sorry for not explaining.

The compiler has directories for headers, source files and library files. I want to be able to put my headers in those directories and just #include <myheader.h> (using <> not ""). So in order to do this I have to create a lib file. My question was, because SDL is a dynamic library (dll), if I have to create a dll as well (because my sprite header file includes SDL.h) and not lib file.
That question right there, that very one you just asked, was answered in my first post. Like I said, you don't have to create a library to use <> instead of "", you just have to put the header's directory in you project/compiler include path (if you don't know how to do this, tell us what IDE or compiler you're using and we can tell you; SiCrane told how to do it for MSVS). And as I said, just because SDL is a .dll, doesn't mean (or require) that your project be a .dll as well. Your project can be a .lib and still use the SDL .dll.

Share this post


Link to post
Share on other sites
Quote:
Original post by MikeTacular
if you don't know how to do this, tell us what IDE or compiler you're using and we can tell you; SiCrane told how to do it for MSVS

Psst. <whisper>Thread title.</whisper>

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
Quote:
Original post by MikeTacular
if you don't know how to do this, tell us what IDE or compiler you're using and we can tell you; SiCrane told how to do it for MSVS

Psst. <whisper>Thread title.</whisper>


Hehe... *facepalm*

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!