Questions tagged [multiple-inclusions]

13 questions
68
votes
6 answers

Why aren't my compile guards preventing multiple definition inclusions?

I have a header file x.h which is included by more than one *.c source files. This header file has some structure variables defined. I have put multiple inclusion prevention guard at the beginning of the header file as: #ifndef X_H #define…
goldenmean
  • 18,376
  • 54
  • 154
  • 211
15
votes
3 answers

What kinds of header files should not be protected against multiple inclusion?

I read the dcmtk source code, and found a comment in ofstdinc.h: // this file is not and should not be protected against multiple inclusion And what kinds of header files SHOULD NOT be protected against multiple inclusion?
sfzhang
  • 669
  • 9
  • 18
15
votes
9 answers

Repeated Multiple Definition Errors from including same header in multiple cpps

So, no matter what I seem to do, I cannot seem to avoid having Dev C++ spew out numerous Multiple Definition errors as a result of me including the same header file in multiple source code files in the same project. I'd strongly prefer to avoid…
Wolerywol
13
votes
4 answers

Linking .h files with .c with #ifdef header guards

im having trouble linking .h and .c files, i've also read some threads regarding this problem and all of them is a bit vague and still i can't fully grasp the concept of it, and im having a lot of linking problems, Say i have b.c and b.h which i…
lemoncodes
  • 2,371
  • 11
  • 40
  • 66
6
votes
4 answers

Avoiding double inclusion: Preprocessor directive vs. makefiles

I'm working on moving from frankenstein and one-file thousands-of-lines programs to well structured and organized, multi-file programs. Right now what seems to be natural (naively) is to make a love-triangle of header inclusions for three of my…
DilithiumMatrix
  • 17,795
  • 22
  • 77
  • 119
3
votes
1 answer

Clang++ updated, can't find certain headers despite them being in the include directory

So I'm on mac and wanted to experiment with the latest llvm release, without having to wait for them to be passed on the xcode command line tools. So I downloaded the LLVM 10 release pre-built binary from their downloads page, and stuck it in a…
2
votes
2 answers

Multiply defined symbols (C++)

I am kinda new and getting some really weird errors in my c++ code. As best as i can tell, they are due to multiple inclusion errors. I have the following files CardBase.h #include #include #include class Class1 { string…
1
vote
2 answers

Multiple inclusion error for header file(s) - C

I have a relatively small project with only a few files (.c and .h). I have been fighting multiple inclusion errors (I think). So, I created a master.h header file that has each of the other header files that are needed. ALL of the header files have…
1
vote
0 answers

Two classes referencing each other: unknown override specifier error

I'm writing a program to schedule nurses in a hospital. I'm stuck with an inclusion loop between two classes, but I don't know where I made an error. There's a nurse class that has an instance of a Preference Profile. This preference profile has a…
Rob
  • 11
  • 2
1
vote
0 answers

Redundant multiple header inclusion prevention in source files?

I found a project with this structure: // Header.h #ifndef HEADER_H #define HEADER_H ... #endif // Source.cpp #ifndef HEADER_H #include "Header.h" #endif To me, this seems to be a bit redundant. Maybe there could be a small performance…
Pietro
  • 12,086
  • 26
  • 100
  • 193
0
votes
1 answer

Best way to check multiple inclusions

#ifndef api_H_ #define api_H_ ... #endif In above code it's checking that if file is already included or not to avoid multiple inclusions. Question: I want to know that if there is any better way to do so and what are the alternatives of it and if…
Nilesh Pal
  • 23
  • 7
0
votes
1 answer

What's the advantage of manually registering resource classes in JAX-RS application?

Excerpt from JEE 7 tutorial: 29.2.7.1 Configuring a JAX-RS Application Using a Subclass of Application ... By default, all the resources in an archive will be processed for resources. Override the getClasses method to manually register the …
user1418717
  • 425
  • 2
  • 5
  • 13
0
votes
0 answers

Multiple inclusion. What would happen if it is allowed?

I'm new to C++ and have been through a lot of articles about multiple inclusion resolutions. I have come across both MACRO and #pragma once method, even experimented them by myself to solve compile time error. However, none of them mention the…
Sithideth Bouasavanh
  • 1,011
  • 1
  • 11
  • 20