Questions tagged [multiple-definition-error]

Refers to a compiler error for multiple declarations of a variable, function, or class in the same program or project. Often meant to be the same, the programmer just accidentally re-initializes the object.

Refers to a compiler error for multiple declarations of a variable, function, or class in the same program or project. Often meant to be the same, the programmer just accidentally re-initializes the object.

To avoid such errors, its advised to use NameSpaces and sometimes a check for existence of declaration before defining the variable, function or class would eliminate such scenarios.

198 questions
57
votes
8 answers

How to prevent multiple definitions in C?

I'm a C newbie and I was just trying to write a console application with Code::Blocks. Here's the (simplified) code: main.c: #include #include #include "test.c" // include not necessary for error in Code::Blocks int main() { …
Jordi
  • 5,846
  • 10
  • 40
  • 41
57
votes
6 answers

"Multiple definition", "first defined here" errors

I have 3 projects: Server, Client and Commons. Making header & source pairs in Commons doesn't cause any problems and I can access the functions freely from both Server and Client. However, for some reason making additional source/header files…
matt-pielat
  • 1,659
  • 3
  • 20
  • 33
29
votes
4 answers

c & c++ default global variable linkage, multiple declaration & definition problem

For example: code1.c / .cpp int a; // ... and so on code2.c / .cpp int a; int main(void) { return 0; } go to compile: $gcc code1.c code2.c # this is fine $ $g++ code1.cpp code2.cpp # this is dead /tmp/ccLY66HQ.o:(.bss+0x0): multiple…
Bossliaw
  • 698
  • 1
  • 10
  • 23
27
votes
4 answers

Multiple definition and header-only libraries

I have a C program with several c and h files. I decided to make one part of the program 'header-only' so I moved the code from c to h. Now I'm getting multiples definition problems and I have no idea why. e.g.: main.c includes utils.h vector.c…
Suugaku
  • 2,667
  • 5
  • 31
  • 33
24
votes
4 answers

Header-only libraries and multiple definition errors

I want to write a library that to use, you only need to include one header file. However, if you have multiple source files and include the header in both, you'll get multiple definition errors, because the library is both declared and defined in…
Epro
  • 673
  • 2
  • 7
  • 9
20
votes
2 answers

Multiple definition of first defined here gcc

I have these files consumer.cpp consumer.hpp defines.hpp main.cpp makefile producer.cpp producer.hpp here's the file defines.hpp #ifndef DEFINES_HPP #define DEFINES_HPP #include #include #include #include…
user1886376
19
votes
5 answers

C++: Multiple definition error for global functions in the header file

This function is global and is defined in the header file (temporarily I want to keep it there). The header file also constitutes a particular class which has inline functions and one of those functions call this global function. The source file…
Aquarius_Girl
  • 21,790
  • 65
  • 230
  • 411
17
votes
7 answers

C++ Qt Multiple Definitions

I'm trying to create a simple GUI application (so far) in Qt with C++ using the MinGW compiler. However, the compiler is informing me that I have a multiple definition of 'WiimoteScouter::WiimoteScouter(QWidget*)' on line 4 of wiimotescouter.cpp. I…
John M.
  • 2,234
  • 4
  • 24
  • 36
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
11
votes
1 answer

Multiple definitions error: one in my file and one in the moc file.

I have a class called FindAndReplaceBar, whose implementation is this: #include "FindAndReplaceBar.h" #include #include #include #include #include…
W.K.S
  • 9,787
  • 15
  • 75
  • 122
11
votes
3 answers

Multiple definition of a const char*

I get the above message linker error for a global const char* HOST_NAME = "127.0.0.1"; I don't think that I have compiled some files twice but here's my definition of the files anyway. main.cpp #include #include #include…
Billy Grande
  • 577
  • 3
  • 11
  • 23
11
votes
4 answers

QtCreator multiple definition build bug

this is my .pro file: QT += core gui widgets TARGET = link_mult_def TEMPLATE = app SOURCES += main.cpp \ path2/file.cpp \ path1/file.cpp HEADERS += For some reason, QtCreator does not respect the source folder…
HenrySpencer
  • 111
  • 2
  • 5
10
votes
1 answer

multiple definition linker error after adding a function to a previously linking file

So my program is working fine. Compiling, linking, running, the works. Then, I decide to add a simple function to one of my files, like this: #ifndef UTILITY_HPP #define UTILITY_HPP /* #includes here. There's no circular include, I've checked.…
Max
  • 1,295
  • 6
  • 16
  • 31
9
votes
1 answer

boost test library: Multiple definition error

I'm trying to test a library that I've done (Calculus), in QTCreator for Windows. I've created a main file, and a class in a separate file for the testing. If I compile the example found in…
Jepessen
  • 11,744
  • 14
  • 82
  • 149
9
votes
2 answers

multiple definition error c++

My 'Headers.h' file includes basic c++ Headers #include #include // and many header files. wrote a function definition for file exist check and saved it in 'common_utility.h' - ifFileExist() common_utility.h bool…
Smith Dwayne
  • 2,675
  • 8
  • 46
  • 75
1
2 3
13 14