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):
I call this header file in other file, which name is main.h like this:
# 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
In the main.c file I have this:
# 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
Where is the problem?
# include "main.h"
int main ()
GotoXY (10, 10);
printf ("HELLO !");
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?
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
Are you sure that you just defined gotoXY() once? and in one file?
Check your header files and see if you declared more times..
Yes I'm sure that GotoXY is declared only once. Is that #ifndef declared ok?
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.
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?