Thread: Header files

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

    Question Header files

    Hi!

    I have big problems with header files. I get compiler errors that GotoXY function is already
    defined in file main.obj.

    I have a header file in the directory <CGE SDK 1.0/cge.h> (CGE SDK 1.0 is the directory under include directory in VC++ .NET).
    It look like this (cge.h):
    Code:
    # ifndef CGE_H
    # define CGE_H
    
    # include <windows.h>
    # include <stdio.h>
    # include <string.h>
    # include <io.h>
    # include <time.h>
    # include <assert.h>
    # include "colors.h"
    # include "dialogbox.h"
    # include "advedit.h"
    
    // ASCII graphical elements for drawing a frame
    # define RIGHT_DOWN_LINE            218
    # define RIGHT_DOWN_DOUBLELINE      201
    # define RIGHT_UP_LINE              192
    # define RIGHT_UP_DOUBLELINE        200
    
    
    // function prototypes
    void GotoXY (short x, short y);
    void ClrScr (short x, short y, short EraseLength, short NoOfLines, WORD EraseColor, char ErasePattern);
    BOOL SetColor (WORD Color);
    
    # endif CGE_H
    I call this header file in other file, which name is main.h like this:
    Code:
    # ifndef MAIN_H
    # define MAIN_H
    
    # include <CGE SDK 1.0/cge.h>
    
    
    // background color for the main menu
    # define MAIN_MENU_COLOR BACK_DARKTURQUIOSE
    
    // setup file
    # define OPTIONS_FILE "./options.ini"
    
    void SnakeLogo (void);
    
    # endif MAIN_H
    In the main.c file I have this:
    Code:
    # include "main.h"
    .
    .
    .
    int main ()
    {
        GotoXY (10, 10);
        printf ("HELLO !");	
        return 0;
    }
    Where is the problem?

    Please help.
    Last edited by GaPe; 01-30-2003 at 10:21 AM.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    You spelled the declaration and the call of GotoXY differently. C/C++ is case sensitive.
    But since the compiler complains about "Multiple declarations", that shouldn't be the real problem. You're using #ifndef/#define:s so that shouldn't happen. Are you sure you're not declaring it elsewhere?
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Yes, You spelled you GotoXY() wrong when calling.
    An error like that means you have a declaration twice in different
    source files in the same project. Source files arent the same as
    header files.

  4. #4
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    Are you sure that you just defined gotoXY() once? and in one file?
    Check your header files and see if you declared more times..

  5. #5
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Yes I'm sure that GotoXY is declared only once. Is that #ifndef declared ok?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  6. #6
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    If GotoXY would be defined multiple times the compiler would
    notice BEFORE linking, if it was in a source file it would notice it
    DURING linking, the answer is obvious.

  7. #7
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    I'm writing a SDK for console. SDK has .c and .h files. Now I'm writing a console program which uses my SDK's libraries and this console program also has .c and .h files.

    Can someone please post me an example how to use all this .c and header files?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. #include header files or .cpp files?
    By DoctorX in forum C++ Programming
    Replies: 3
    Last Post: 12-23-2006, 12:21 PM
  3. classes and header files
    By Drake in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2006, 07:12 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM