hey every1! iv never posted on this site before but have view the site and have benifitted from the help given here. hope some1 can help me with this prob!

Ok, i have 2 files, 1 which i want 2 contain arrays of words, and the other to contain the main program. I want to link to these arrays and select words from them randomly.

I canget everything working except the linking.

Heres what i have at the min, along with the errors i get! ive tried changing it a few times but cant understand why it wont work.

1st file (declarations)

#ifndef gM
char NOUN[5][6] ={"noun1","noun2","noun3","noun4","noun5"};	
#endif

#ifndef gM
char VERB[5][6] ={"verb1","verb2","verb3","verb4","verb5"};
#endif

#ifndef gM
char ADJ[5][6] ={"adjt1","adjt2","adjt3","adjt4","adjt5"};
#endif

#ifndef gM
char PREP[5][6] ={"prep1","prep2","prep3","prep4","prep5"};
#endif

#ifndef gM
char AVRB[5][6] ={"avrb1","avrb2","avrb3","avrb4","avrb5"};
#endif

2nd file (containing main program)

//Declare variables and initalise
	extern char NOUN[5][6];
	extern char VERB[5][6];
	extern char ADJ[5][6];
	extern char PREP[5][6];
	extern char AVRB[5][6];

error:
f2.obj : error LNK2005: _AVRB already defined in f1.obj
f2.obj : error LNK2005: _PREP already defined in f1.obj
f2.obj : error LNK2005: _ADJ already defined in f1.obj
f2.obj : error LNK2005: _VERB already defined in f1.obj
f2.obj : error LNK2005: _NOUN already defined in f1.obj
f1.exe : fatal error LNK1169: one or more multiply defined symbols found

what am i doing wrong? thanks!

Recommended Answers

All 2 Replies

It's unclear where global array definitions were placed. Probably, these #ifndef...char[][]={}...#endif chain was placed twice.
Place extern declarations only fragment in separated .h file, include it in .c modules where external arrays access needed. External arrays definitions (declarations with initialization) must be placed in one and only one source file (it's c-file, not h-file).
Next time try to describe your project file structure more clearly.
That's all.

> char NOUN[5][6] ={"noun1","noun2","noun3","noun4","noun5"};
These go in exactly ONE .c file, and without all the #ifdef stuff.

> extern char NOUN[5][6];
These go in a header file, to be included in all the files which need to access NOUN.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.