Pages: [1]
  Print  
Author Topic: Error: multiple definition of  (Read 366 times)
Offline (Unknown gender) TheExDeus
Posted on: December 26, 2011, 06:30:08 PM

Contributor
Joined: Apr 2008
Posts: 559

View Profile
I ALWAYS get errors like this with ENIGMA when I am making something. And I am never able to fix these. Google search revelaed that is means what it says it means - I have multiple definitions of some structure or the like. This problem arrises when I include the first.h file (where structs are declared) into another second.h file and then include that second.h inside a project where I inclued the first.h then I will have two declarations of the same thing. The twist though, is that I DON'T. I think ENIGMA does include it somewhere, but I don't. The file structure:
include.h
main_code.cpp
I have #include "include.h" inside main_code.cpp. That is it. I don't include that "include.h" anywhere else. This is an extension though, so I have this in the Makefile:
Quote
SOURCES += $(wildcard Universal_System/Extensions/SomeExtension/main_code.cpp)
ifeq ($(PLATFORM), Win32)
   LDLIBS += $(wildcard Universal_System/Extensions/SomeExtension/libs/*.a)
endif
This is it.

So for the love of anything - WHY the hell it trows this error? I had this problem when I added surfaces as well. That is why it took me more than a year to add that god damn FBO support.

edit: It shows:
.eobjs/Windows/Windows/Run/SHELLmain.o:SHELLmain.cpp:(.text+0x6): first defined here
So ENIGMA includes the include.h inside the SHELLmain.cpp even when I don't ask it to? It would be fine if it did that and I could leave out #include "include.h" in the .cpp, but then it errors that I don't have struct's defined. So I either don't have them defined, or I have defined them twice. I don't really have a choice there.

edit2: I also tried "include guard" technique. So I had:
#ifndef MYFILE_H
#define MYFILE_H
//contents of include.h
#endif
And it still had the same error. This doesn't even make sense, because I can't have included it twice in this case.
« Last Edit: December 26, 2011, 06:37:15 PM by HaRRiKiRi » Logged
Offline (Unknown gender) TheExDeus
Reply #1 Posted on: December 27, 2011, 10:05:06 AM

Contributor
Joined: Apr 2008
Posts: 559

View Profile
......................
Logged
Offline (Male) Josh @ Dreamland
Reply #2 Posted on: December 27, 2011, 10:45:10 AM

Prince of all Goldfish
Developer
Location: Ohio, United States
Joined: Feb 2008
Posts: 2276

View Profile Email
It doesn't matter if you guard it if you are including the header from two source files.
Don't declare globals in headers, except with extern.
Don't implement functions in headers unless they are static and/or inline.
Logged
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble
"I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
Offline (Unknown gender) TheExDeus
Reply #3 Posted on: December 27, 2011, 03:19:35 PM

Contributor
Joined: Apr 2008
Posts: 559

View Profile
Quote
It doesn't matter if you guard it if you are including the header from two source files.
But where do I do this? I have only one place I include it (I have only one .cpp file). I think ENIGMA includes the header somewhere as well as part of the extensions system, and that is what causes me the trouble.

Quote
Don't declare globals in headers, except with extern.
I don't declare any globals in headers.
Quote
Don't implement functions in headers unless they are static and/or inline.
I do have functions there for structs. Like grid::grid(). I will try to move them in the .cpp and see what happens.

edit: That did it. I don't know what else includes the header, but that was frustrating.
« Last Edit: December 27, 2011, 03:26:13 PM by HaRRiKiRi » Logged
Offline (Male) Rusky
Reply #4 Posted on: December 27, 2011, 07:00:54 PM
Resident Troll
Location: Airship Abubalay
Joined: Feb 2008
Posts: 806
MSN Messenger - rpjohnst@gmail.com
View Profile WWW Email
Surround the contents of the header file with
Code: [Select]
#ifndef HEADER_NAME_H
#define HEADER_NAME_H
Code: [Select]
#endif...just in the general case.
Logged
[www.abubalay.com]

Time traveling to Feb. 2014, back later.
Offline (Unknown gender) TheExDeus
Reply #5 Posted on: December 27, 2011, 07:51:40 PM

Contributor
Joined: Apr 2008
Posts: 559

View Profile
That is what I did previously. Didn't help. For some unknown reason it still got included twice.
Logged
Offline (Male) Rusky
Reply #6 Posted on: December 27, 2011, 09:39:43 PM
Resident Troll
Location: Airship Abubalay
Joined: Feb 2008
Posts: 806
MSN Messenger - rpjohnst@gmail.com
View Profile WWW Email
In addition to not implementing non-static, non-inline functions in headers, of course.

If a function like that is in a header file it will exist in multiple object files and the linker will complain.

That's different from being #included twice.
Logged
[www.abubalay.com]

Time traveling to Feb. 2014, back later.
Pages: [1]
  Print