I have a .h file which I was intending to use only for storing all the information string that will be displayed in my program. In my info.h:
#ifndef __INFO_H
#define __INFO_H
char *info_msg = "This is version 1.0 of NMS.";
//all other strings used by view.c and controller.c
#endif
Then in my view.h I have as follows:
//view.h
#ifndef __VIEW_H
#define __VIEW_H
#include "info.h"
//other stuff like method declaration etc.
#endif
My controller.h is using view.h:
//controller.h
#ifndef __CONTROLLER_H
#define __CONTROLLER_H
#include "view.h"
#include "model.h"
//other stuff line method declaration etc.
#endif
main.c:
#include "controller.h"
int main()
{
//stuff
}
view.c:
#include "view.h"
char esc,up,down,right,left;
void change_character_setting(char pesc, char pup, char pdown, char pright, char pleft)
{
esc = pesc;
up = pup;
down = pdown;
right = pright;
left = pleft;
}
void print_warning()
{
printf("%s \n",info_msg);
}
When I attempt to create the executable the linker complains:
/tmp/ccqylylw.o:(.data+0x0): multiple definition of `info_msg'
/tmp/cc6lIYhS.o:(.data+0x0): first defined here
I am not sure why it would see two definitions since I am using the protection block. I tried to google here but nothing specific showed up. Can someone explain how it is seeing multiple definitions? How do I achieve something as simple in Java to use one single file for all text manipulation in C?