Thread: How To use #ifdef ?

  1. #1
    Code Warrior
    Join Date
    Nov 2001

    Question How To use #ifdef ?


    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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    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

    /* stuff you want for dll builds */
    extern int var;
    /* stuff you want for lib builds */
    static int var;
    /* 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.

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, 03: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, 02: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