Compilation Error. Need help

This is a discussion on Compilation Error. Need help within the C Programming forums, part of the General Programming Boards category; Ok. I'm doing a Towers of Hanoi project and it's supposed to be a multi file program. I keep getting ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    19

    Compilation Error. Need help

    Ok. I'm doing a Towers of Hanoi project and it's supposed to be a multi file program. I keep getting this error and I can't figure out why.
    hanoi.c:4: error: redefinition of ‘hanoi’
    hanoi.h:5: error: previous definition of ‘hanoi’ was here
    Here's the code for hanoi.h
    Code:
    void makeMove(int, int);
    void hanoi(int, int, int, int);
    
    
    extern in n;
    extern int noOfMoves;
    enum stacks{A = 1, B, C};
    and for hanoi.c
    Code:
    #include "hanoi.h"
    
    void hanoi(int n, int src, int dest, int by)
    {
            if(n == 1)
            {
                    makeMove(src, dest);
            }
            else
            {
                    hanoi(n - 1, src, by, dest);
                    makeMove(src, dest);
                    hanoi(n-1, by, dest, src);
            }
    }

  2. #2
    Registered User
    Join Date
    Apr 2007
    Posts
    51
    What does the rest of it look like?

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    278
    do you inlcude hanoi.h in another .c file? If so, you're loading the definitions within hanoi.h twice... in hanoi.h add the following to the TOP of the file

    Code:
    #ifndef __HANOI_H     // or some other unique identifier
    #define __HANOI_H
    then at the VERY BOTTOM of hanoi.h add
    Code:
    #endif
    This will prevent the error you're experiencing

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,442
    Quote Originally Posted by Bladactania
    in hanoi.h add the following to the TOP of the file
    Names that contain consecutive underscores, or that begin with an underscore followed by an uppercase letter, are reserved to the implementation for any use. As such, even though it is unlikely to matter, I would suggest removing those two leading underscores from the header inclusion guard macro name.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Feb 2009
    Posts
    278
    I wasn't aware of that. Thanks...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. PC RAM in Compilation
    By SlyMaelstrom in forum Tech Board
    Replies: 5
    Last Post: 05-21-2006, 06:03 AM
  2. Inconsistent Compilation
    By GlassEyeSlim in forum Linux Programming
    Replies: 2
    Last Post: 02-23-2006, 05:43 PM
  3. Compilation units
    By filler_bunny in forum C++ Programming
    Replies: 0
    Last Post: 10-21-2003, 03:57 AM
  4. MS VC++ Crash on compilation
    By Magos in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 08-23-2003, 07:06 PM
  5. malloc problem in SUN in 64-bit compilation
    By ylzhang in forum C Programming
    Replies: 6
    Last Post: 05-31-2003, 11:48 AM

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