Why every first function of each file get error of"Multiple Definition of 'void pointer'"

I declared all functions in header file, such as:
1
2
3
4
5
6
7
8
9
bool readCase();

bool meshing();
bool readMesh();

bool calculateFlowfield();
bool readFlowfield();

bool calculateEvaporation();


and then I define them in separated .cpp files, each .cpp file include the header, but I got multiple definition error, why?

Even the int main() function, which only decalred and defined once got this error, why?

Urgent!!! Please save me!
Last edited on
This header file is not what causes the error. Have you defined a void* somewhere?
Thanks.

I have the guards, and never have a void*.
Are you getting the error from the compiler or the linker?
Please post the exact text of the error.

Not sure what void* has do do with anything here unless that was edited out of the original post.
I guess it is from Linker!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
11:26:08 **** Incremental Build of configuration Debug for project T101_FirstAll ****
make all 
Building target: T101_FirstAll
Invoking: GCC C++ Linker
g++  -o "T101_FirstAll"  ./src/BoundaryCondition.o ./src/CalculateEvaporation.o ./src/CalculateFlowfield.o ./src/FiniteVolume.o ./src/Geometry.o ./src/Meshing.o ./src/Physics.o ./src/PoreThroat.o ./src/T101_FirstAll.o   
./src/CalculateEvaporation.o: In function `calculateEvaporation()':
/home/david/Work/KeplerSpace/T101_FirstAll/Debug/../src/CalculateEvaporation.cpp:12: multiple definition of `voidPointer'
./src/BoundaryCondition.o:/home/david/Work/KeplerSpace/T101_FirstAll/Debug/../src/BoundaryCondition.cpp:17: first defined here
./src/CalculateFlowfield.o: In function `calculateFlowfield()':
/home/david/Work/KeplerSpace/T101_FirstAll/Debug/../src/CalculateFlowfield.cpp:13: multiple definition of `voidPointer'
./src/BoundaryCondition.o:/home/david/Work/KeplerSpace/T101_FirstAll/Debug/../src/BoundaryCondition.cpp:17: first defined here
./src/Geometry.o: In function `__gnu_cxx::new_allocator<point_c>::new_allocator()':
/home/david/Work/KeplerSpace/T101_FirstAll/Debug/../src/Geometry.cpp:17: multiple definition of `voidPointer'
./src/BoundaryCondition.o:/home/david/Work/KeplerSpace/T101_FirstAll/Debug/../src/BoundaryCondition.cpp:17: first defined here
./src/Meshing.o: In function `__gnu_cxx::new_allocator<block_c>::new_allocator()':
/home/david/Work/KeplerSpace/T101_FirstAll/Debug/../src/Meshing.cpp:30: multiple definition of `voidPointer'
./src/BoundaryCondition.o:/home/david/Work/KeplerSpace/T101_FirstAll/Debug/../src/BoundaryCondition.cpp:17: first defined here
./src/Physics.o: In function `operator>>(std::istream&, material_c&)':
/home/david/Work/KeplerSpace/T101_FirstAll/Debug/../src/Physics.cpp:13: multiple definition of `voidPointer'
./src/BoundaryCondition.o:/home/david/Work/KeplerSpace/T101_FirstAll/Debug/../src/BoundaryCondition.cpp:17: first defined here
./src/PoreThroat.o: In function `std::vector<unsigned long, std::allocator<unsigned long> >::operator[](unsigned long)':
/home/david/Work/KeplerSpace/T101_FirstAll/Debug/../src/PoreThroat.cpp:17: multiple definition of `voidPointer'
./src/BoundaryCondition.o:/home/david/Work/KeplerSpace/T101_FirstAll/Debug/../src/BoundaryCondition.cpp:17: first defined here
./src/T101_FirstAll.o: In function `__gnu_cxx::new_allocator<throat_c>::new_allocator()':
/home/david/Work/KeplerSpace/T101_FirstAll/Debug/../src/T101_FirstAll.cpp:39: multiple definition of `voidPointer'
./src/BoundaryCondition.o:/home/david/Work/KeplerSpace/T101_FirstAll/Debug/../src/BoundaryCondition.cpp:17: first defined here
collect2: error: ld returned 1 exit status
make: *** [T101_FirstAll] Error 1

11:26:08 Build Finished (took 209ms)
Last edited on
What's at BoundaryCondition.cpp line 17?
ostream & operator << (std::ostream & os, const CBC_c & b) {

This is BoundaryCondition.cpp line 17

The error lines printed are all where the first function of that file is defined. Very Strange!
Last edited on
What does the CBC_c class declaration look like?

What is at some of the other source references mentioned by the linker?
CalculateEvaporation.cpp:12
CalculateFlowfield.cpp:13
Geometry.cpp:17
Meshing.cpp:30
Physics.cpp:13
PoreThroat.cpp:17
T101_FirstAll.cpp:39

Sorry to be tedious about this, but short of posting all your code, the only option is to drill down piece by piece.
1
2
3
4
5
6
7
8
9
10
11
12
13
bool calculateEvaporation() {

bool calculateFlowfield() {

istream & operator >> (istream & is, point_c & p) {

bool meshing() {

istream & operator >> (istream & is , material_c & m) {

bool pore_c::setPosition(const position_e & pos) {

int main() {


Thanks very much, AbstrationAnon, for drill them piece by piece for me. they are all about function definition
Have you tried doing a clean build not am Incremental one?
> but short of posting all your code
I would prefer a minimal setup that reproduces the problem, but if that is too much to ask, then posting the full code is the first thing to do.
The first supposition is that you are doing something wrong. To know what you are doing wrong, we need to know what you are doing.

So we need your code, and the commands that you are using to build, and the error messages that you are receiving.
We shouldn't need to ask for them.


> The error lines printed are all where the first function of that file is defined. Very Strange!
the message is not relevant apart from stating the repeated symbol and the object file where it is defined.


As a guess, you've got a variable named `voidPointer' (note, no spaces like in the topic title) that you defined in a header file, instead of declaring it as extern.
All the sources that include that header define the variable on their own, and then clash.
ne555, How did you know? You are real amazing! Thanks!!!

Yes, I defined a const void* voidPointer(0);

After I comment it, everything is fine now.

But I am wondering, this is a const. And when it is const, there should be no need to use extern, right? All my other const didn't use extern and got no problems. Why?
> Yes, I defined a const void* voidPointer(0);
> But I am wondering, this is a const. And when it is const, there should be no need to use extern, right?

It is not a const. It is a non-const pointer to const void.

This is a const pointer to const void: const void* const pointer = nullptr ;
Thanks, JLBorges, I made the mistake again!
Topic archived. No new replies allowed.