Thread: Good Practice With Include Files

  1. #1
    Amazingly beautiful user.
    Join Date
    Jul 2005
    Location
    If you knew I'd have to kill you
    Posts
    254

    Good Practice With Include Files

    I'm writing a library, which has the ability to interoperate with SDL, but in the event that SDL does not exist, is still useful on its own. I want to have it build regardless of whether or not SDL exists, and simply disable functionality.

    So far, I have the SDL extensions inside an #ifdef which checks for _SDL_H (SDL.h defines this). I include SDL with the statemene
    Code:
    #include "SDL.h"
    Then, I create a folder, "dummy," in which I have a blank file called "SDL.h" The Makefile adds "dummy" to the build path, but after everything else. That way, if the user adds an -I/usr/include/SDL (or whatever form your operating system works with), it gets built with the SDL extensions, but if not, it builds without them. Is this a bad way of implementing everything?
    Programming Your Mom. http://www.dandongs.com/

  2. #2
    Registered User
    Join Date
    Dec 2002
    Posts
    8
    It's not really a bad way, although it'd probably be easier to just have your own definition for SDL.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    why not just do this:
    Code:
    #ifdef MYPROG_SDL_SUPPORT
    #include "SDL.h"
    #endif

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Most of the time, what you want to do is "check if there is SDL installed" and set a "CONFIG_HAS_SDL" or some such define on the command-line (or in a "config.h"), so that later on you can do something like:

    Code:
    #if CONFIG_HAS_SDL
       #include <SDL.h>
    #endif
    ...
    #if CONFIG_HAS_SDL
        .... // some SDL-related code
    #endif
    --
    Mats

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2d game
    By JordanCason in forum Game Programming
    Replies: 5
    Last Post: 12-08-2007, 10:08 PM
  2. include files that are'nt in compiler's directory
    By vaibhav in forum C++ Programming
    Replies: 10
    Last Post: 03-25-2006, 11:45 AM
  3. MFC include BS
    By VirtualAce in forum Windows Programming
    Replies: 4
    Last Post: 10-31-2005, 12:44 PM
  4. include library header in header files
    By Raison in forum C++ Programming
    Replies: 6
    Last Post: 09-27-2004, 02:50 AM