Questions tagged [include-guards]

Anything related to C/C++ include guards technique, i.e. a technique employing C-preprocessor conditional compilation features in order to prevent multiple inclusion of header files in C/C++ source files.

Anything related to C/C++ include guards technique, i.e. a technique employing C-preprocessor conditional compilation features in order to prevent multiple inclusion of header files in C/C++ source files.

185 questions
0
votes
4 answers

How to reduce compile time for large C++ library of individual .cpp files?

We're developing a C++ library with currently over 500 hundred individual .cpp files. These are each compiled and archived into a static library. Even with a parallel build, this takes some minutes. I'd like to reduce this compilation time. Each…
0
votes
1 answer

C++ include guards and multiple definition errors

I have a situation where I need to include a header file (stack.h) in 2 .cpp files. The set up is as below: //------"stack.h"------// std::stack s; int a; void doStackOps(); void print(); //------"stack.cpp"------// #include…
ggog
  • 13
  • 4
0
votes
2 answers

c++ template and include guards

I am relatively new to C++, so my question may have an easy answer; however, I cannot find out why my code is not working when I thought it should. Sample code is as follows. //a.h #ifndef A #define A template class a{ public: …
ew820513
  • 13
  • 4
0
votes
1 answer

Include Problems and Include Guards

My team and I are working on a pretty large project with many classes with their respective header and source files. We are trying to consolidate all includes from both C++ libraries and the projects class header files into one file called…
0
votes
5 answers

Multiple Include Optimization

I'm trying to understand how multiple-include optimization works with gcc. Lately, I've been reading a lot code that has include guards for standard header files like so #ifndef _STDIO_H_ #include #endif and I'm trying to figure out if…
dinesh
  • 765
  • 2
  • 9
  • 21
0
votes
4 answers

Why include guards gives no effect for me? Am I missing something?

MainGame.h #ifndef MainGame_h #define MainGame_h #include #include #include "Horde3D.h" //definitions #endif MainGame_h MainGame.cpp #include #include #include "Horde3DUtils.h" #include "MainGame.h" #include…
Kosmo零
  • 4,001
  • 9
  • 45
  • 88
0
votes
3 answers

Will ifndef always work on an object-like macro defined with an empty replacement-list

Include guards in header files are often used to protect sections of code from double inclusion: #ifndef FOOBAR_H #define FOOBAR_H extern void myfoofunc(void); #endif Include guards typically rely on the expectation that if an object-like macro…
Vilhelm Gray
  • 11,516
  • 10
  • 61
  • 114
0
votes
1 answer

#include repetition

Context: I've got one class which has two include clauses: #ifndef VAR_RECORD_SONG_H #define VAR_RECORD_SONG_H #include "VarRecord.h" #include "Compressor.h" class VarRecordSong : public VarRecord { public: VarRecordSong(); …
Maria Ines Parnisari
  • 16,584
  • 9
  • 85
  • 130
0
votes
3 answers

Find include guard typos in C++ with gnu coreutils

Below is a typo for a C++ include guard. Both should read _MYFILE_H_. #ifndef _MYFILE_H_ #define _MYFLIE_H_ How would you suggest searching a bunch of header files for a typo like this using GNU coreutils (e.g. grep, awk)?
Shaun Lebron
  • 2,501
  • 28
  • 29
0
votes
1 answer

C - #include and multiple typedefs

I'm writing an embedded C program in eclipse with gcc and can't see how to get around a certain issue. I have a typedef in a header file which is protected by an include guard. Since I use this typedef in multiple headers, I need to include it in…
0
votes
1 answer

C++ with Extern "C" causing Duplicate Symbols Error

I am trying to use a extern "C" function inside my header file for a c++ class. When I compile I keep getting the error duplicate symbol _currentInstance in: main.o GLHandler.o I thought I had the right guards but can't seem to figure out why this…
BJacobs
  • 122
  • 1
  • 8
0
votes
1 answer

header file include-loop and multiple definition

I have a util.h containing a function which will be used in a.h and 'b.h', and further more, a.h and b.h will include each other in order to access some classes defined in each other. //util.h #ifndef _UTIL_H_ #define _UTIL_H_ #include…
Alcott
  • 17,905
  • 32
  • 116
  • 173
0
votes
2 answers

Are there include guards in the standard headers/libraries?

By the fact if I include stdlib.h into each file of my program and I do not get an re-definition error. So, the answer is yes. Right? I'm reading the libxml2 source code, and in HTMLparser.c there is this part: #include #ifdef…
Jack
  • 16,276
  • 55
  • 159
  • 284
0
votes
3 answers

Why is it not permitted to define the members of a C struct more than once?

The rule in C against declaring a struct's members more than once seems to me to be the main reason that include guards are necessary. If we have the following in "header.h": struct s { int a; char b; }; and the file "a.h" #include's…
Gavin Smith
  • 3,076
  • 1
  • 19
  • 25
-1
votes
2 answers

Include Guard Problem in C (Compiler still reports redefiniton errors)

AS the title says I am having an issue using include guards. I was not sure if I was using them correctly and so I have already checked several related posts and they all contain code that seems to be the same as mine. Please advise me as to what is…
1 2 3
12
13