Public Group

#### Archived

This topic is now archived and is closed to further replies.

This topic is 5983 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello! I have moved all my prototypes into a header file, and that header is included in all my code files. But when i try to compile the compiler gives me the error that all my prototypes are already defined. I guess this is because they are inculded in several files. How can i solve this? Thanks! //olle

##### Share on other sites
Use something like this:

  #ifndef _SOME_H_#define _SOME_H_// Your prototypes#endif

Those who do not love don''t live.

##### Share on other sites
Hello! im sorry, I dont understand. what do I replace _SOME_H_ with?

##### Share on other sites
Hey!

What LordLethis means is that you can use whatever you want, but it''s easier to use descriptive names. For example, if you want to include myhead.h, put

at the beginning and end of myhead.h.
What this does is that the header file is only included once per compile.

##### Share on other sites
Exactly.

You can use anything except reserved keywords instead of _SOME_H_.

And if this does not solve the problem and if your using MSVC, set the option /force:multiple in the linker options.

Those who do not love don''t live.

##### Share on other sites
Hello. Im afraid i still dont get it. :|
I have three prototypes. Every one of those functions are in its own file, and prototypes.h is my header file containing them. Prototypes.h looks like this now:

#ifndef prototypes_h
#define prototypes_h

int Game_Init();
int Game_Shutdown();
int Game_Main();

#endif prototypes_h

So now i should use: ''#include "prototypes_h" '' in all my code files right? But that gives me this error:

fatal error C1083: Cannot open include file: ''prototypes_h'': No such file or directory

What am i doing wrong?

Thanks!

##### Share on other sites
The filename is still "prototypes.h"(notice the full stop instead of the underscore) - so it should be #include "prototypes.h"

"The churches used to win their arguments against atheism, agnosticism, and other burning issues by burning the ismists, which is fine proof that there is a devil but hardly evidence that there is a God."
Ben Lindsey and Wainwright Evans

##### Share on other sites
No, keep including "prototypes.h", since that''s the actual file you''re using.

What you were being told to do was add some preprocessor commands. These commands go to the compiler and help it decide what code to use when.

In this case, the prototype_h is just the name of a flag. When you say #ifndef prototype_h, you are asking the compiler to use all of the code up to the #endif if and only if prototype_h hasn''t been defined before. The next command (#define prototype_h) defines it. By doing this, it ensures that if it ever gets to the #ifndef line again, it will already be defined and hence skip the code in the header. So no matter how many files include "prototype.h", the prototypes in it will only be declared once.

-Auron

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633677
• Total Posts
3013284
×