![]() |
|
#1
|
|||
|
|||
Linker errors with multiple file progamHi,
I am trying to compile a program having multiple files. I have a common header file which i am including in 3 source files. Multiple inclusion is protected by wrapping the contents of .h file using "#ifndef" For e.g. I have following in my header file CPP / C++ / C Code:
How ever I am getting linker errors for multiple inclusion of above array and similar other arrays. Quote:
Can some one help me to figure out where the problem is? Thanks, |
|
#2
|
||||
|
||||
|
Quote:
Never define data in your header file. They are for delarations only. Put the contents of your header file in one of the source files and change all definitions to externals: CPP / C++ / C Code:
The wrapping, called header guards only prevent inclusion in the same source file. They are used when you have a complicated set of headers, and the possibility of a header being including more than once because of nested headers (headers including headers which include more headers). What you tried to do is prevent the multiple definitions in the other files. If it worked the way you expected, none of the variables would have been defined in 2 of the three files. You might as well just leave the .h file out. What you in fact did is define the variables control_reply_result_codes, general_error_codes, et al in each source file. Complete with your string definitions. The .h files should not "reserve variable space", only declare the variable exists. The source files reserve the space. __________________
Cow: You're a lawyer too? Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase! |
|
#3
|
|||
|
|||
Thanks. That worked.Hi Walt,
Thanks. That did the trick. It is my first attempt to write a program that spans more than 2 source files. Good I got things cleared now. Much appricated. Thanks, |
Recent GIDBlog
Last Week of IA Training by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Airport Log program using 3D linked List : problem reading from file | batrsau | C Programming Language | 11 | 29-Feb-2008 07:44 |
| CD burner wont burn!! | robertli55 | Computer Hardware Forum | 1 | 18-Jun-2004 10:53 |
| Yet another CD burner problem: Lite-On LSC-24082K | Erwin | Computer Hardware Forum | 1 | 22-May-2004 11:28 |
| Re: Programming Techniques | WaltP | C Programming Language | 0 | 09-Mar-2004 23:56 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The