How To use #ifdef ?

This is a discussion on How To use #ifdef ? within the Windows Programming forums, part of the Platform Specific Boards category; Hi! I have a project, and I want that the source code of this project can be compiled as .lib ...

  1. #1
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669

    Question How To use #ifdef ?

    Hi!

    I have a project, and I want that the source code of this project can be compiled as .lib file or .dll file. How do I do this?

    I think that I should use # ifdef and stuff like that, but I don't know how to declare that.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,761
    Well you create a lib project and a dll project

    You add all your source files to both of them

    You tweak the code so that the lib project builds correctly

    You then try and tweak the code so that the dll project builds correctly, but any changes you make are put inside conditional compilation

    Say, for the sake of argument, that something should be static in a lib, but extern in a dll, then you would do this

    Code:
    #if BUILDING_DLL
    /* stuff you want for dll builds */
    extern int var;
    #else
    /* stuff you want for lib builds */
    static int var;
    #endif
    /* stuff common to both */
    void foo ( void ) {
        var = 1;
    }
    Then you edit the dll project, and in the 'additional pre-processor switches', you add BUILDING_DLL
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. #ifdef DEBUG
    By lehe in forum C++ Programming
    Replies: 4
    Last Post: 06-09-2009, 04:26 PM
  2. ifdef is harmful - but simple workaround is not working
    By amitbern in forum C Programming
    Replies: 15
    Last Post: 12-06-2008, 07:02 AM
  3. #ifdef - Can It Be Used With Logic Such as OR / AND?
    By dedham_ma_man in forum C Programming
    Replies: 3
    Last Post: 04-21-2006, 03:57 PM
  4. Use of #ifdef for portability - a specific case
    By hzmonte in forum C Programming
    Replies: 7
    Last Post: 11-03-2005, 11:24 PM
  5. Difference between ifdef and if defined?
    By z33z in forum C++ Programming
    Replies: 6
    Last Post: 10-28-2001, 11:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21