This topic is 4680 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi, I'm not sure what forum to put this under, but I'm getting a really frustrating error I can't get rid off. It reads like: Fickleton error LNK2005: "public: void __thiscall world::removeGoal(class goal)" (?removeGoal@world@@FQAEXVgoal@@@Z) already defined in Gameworld.obj There are 25 errors, 24 of which are 2 occurences of class functions like the ones above, then one final that says: Fickleton fatal error LNK1169: one or more multiply defined symbols found I only have three files, because I've been trying to compress the files to get rid of this error to no avail. I have a main cpp file which includes only: windows.h, gl/gl.h, and a custom cpp file. This cpp file has #ifndef/#define/#endif statements in it and includes only my custom header. This is ALSO covered with #ifndef/#define/#endif statements and includes only vector, stdlib, and using namespace std. What is wrong with this picture?

Share on other sites
Ok, I have no idea what the problem is - I've gone as far as to compact it all to one cpp file for main to include and it STILL says already defined... what's up?

Share on other sites
The problem is that you should not include a .cpp file in your main file to compile it if it is still part of the workspace. So if you are using Visual Studio, you will need to disable the Build process of that file. More than likely, you should not be including the .cpp file from your main, just the custom header file. The only reason for including a .cpp file is if you happen to be using a library that you need to compile your code before it compiles its code to aviod memory problems (as I had to do for Ogre).

So it should work like this:
// Main.cpp#include "custom.h"...// Custom.cpp#include "custom.h"...// Main.h...// Custom.h...

Kind of see what I mean?

Share on other sites
Files:

Main.cpp
Gameworld.cpp - the implimentations of whats declared in the .h
Gameworld.h

I've collapsed it all down to just main.cpp and gameworld.h at one point and it still won't work. It still gives me the exact same number of linker errors. I have to make main include gameworld.cpp which in turn includes the .h because otherwise I get over a hundred errors. There has to be some trick I'm missing.

Edit: just so you know, the .h only contains class declarations. The cpp contains the implementations of those functions.

Share on other sites
Did you try just including the .h in main?

Share on other sites
Quote:
 Original post by JimmyFoI've collapsed it all down to just main.cpp and gameworld.h at one point and it still won't work. It still gives me the exact same number of linker errors. I have to make main include gameworld.cpp which in turn includes the .h because otherwise I get over a hundred errors. There has to be some trick I'm missing.

"Main.cpp" should only include "Gameworld.h"
"Gameworld.cpp" should only include "Gameworld.h"
"Gameworld.h" should not include either "Gameworld.cpp" nor "Main.cpp"

If you add the .cpp and .h files to your workspace, everything should work fine. If not, please paste the new errors or code using the [source] [/source] tags so we can clear it up for you.

Share on other sites
I just wanted to thank Dave Hunt for his helpful post. I had the same problem JimmyFo had and it was getting on my nerves but the article he linked to fixed everything (it involves using extern). Here's a direct link to the solution (see "Fixing Problem 4" about halfway down the page).