Error LNK2005 and fatal error LNK1169 when debugging

Problems building or running the engine, queries about how to use features etc.
Post Reply
Darkatom
Gnoblar
Posts: 6
Joined: Fri Jul 25, 2014 3:48 am

Error LNK2005 and fatal error LNK1169 when debugging

Post by Darkatom »

Hi, everyone! I'm Darkatom, I'm starting with Ogre3D (really, just starting) because I'm really interested in doing 3D games, at least learn to handle a 3D engine so when the time comes programming is my worst problem and not learning.

So, I started with Ogre3D. I setup a project in Visual C++ 2008 Express Edition, using the Ogre App Wizard (vc9 if I recall correctly). I use OgreSDK_vc9_v1-7-1. I debugged, had to change the name of a folder in my SDK from boost_1_4_7 (or something like that) to boost so the wizard would do it automatically. And I debugged, and executed, and I saw the Ogre Head. Great!

Then I started programming. A main.cpp with this code:

Code: Select all

#include "OGRE\ExampleApplication.h"

class Example1 : public ExampleApplication
{
	public:
		void createScene()
		{}
};

int main (void)
{
	Example1 app;
	app.go();
	return 0;
}
And debugged. I get this two errors:
1>Linking...
1>OIS_d.lib(OIS_d.dll) : error LNK2005: "public: class OIS::MouseState const & __thiscall OIS::Mouse::getMouseState(void)const " (?getMouseState@Mouse@OIS@@QBEABVMouseState@2@XZ) already defined in BaseApplication.obj
1>bin\Debug\First_Ogre3DApp.exe : fatal error LNK1169: one or more multiply defined symbols found
I've tried deleting, commenting and adding includes, I commented the OISMouse include in BaseApplication.h (gave me an error because it could not find mouse's functions, etc.), I've looked into BaseApplication.cpp. Maybe I'm blind, or I just don't get where the problem is. I've been looking around for a solution for a couple of days now, no solution found.

Can anyone help me, please? I would be most grateful.

Thank you,
Darkatom.
Darkatom
Gnoblar
Posts: 6
Joined: Fri Jul 25, 2014 3:48 am

Re: Error LNK2005 and fatal error LNK1169 when debugging

Post by Darkatom »

Help, please? I have been looking too for another way of starting a project that might give me a clue or just be another base for learning. Any of those would be helpful too but I have not been able to find any that helps.
User avatar
LJS
Greenskin
Posts: 138
Joined: Wed Jan 09, 2013 8:58 pm
x 6

Re: Error LNK2005 and fatal error LNK1169 when debugging

Post by LJS »

As the temperature has dropped and my brain is getting unfrozen I am happy, and because I got a kudos for a noob question I asked a long time ago I will pay off the debt, and you propably weren't be able to read the phrase 'learn c++ first' as you started at the wrong place, so I give you three hints;

1. bing.com
2. LNK2005
2.5. LNK1169
3. Basic Tutorials

and an additional tip: Do at least some research before writting down 'help'.

R,

PS I know, I can't count
(am very clumbsy, especially with words on a static screen.)
Ogre 3D 1.9.0 static
Bullet 2.8 static
Darkatom
Gnoblar
Posts: 6
Joined: Fri Jul 25, 2014 3:48 am

Re: Error LNK2005 and fatal error LNK1169 when debugging

Post by Darkatom »

The thing is that, hey! I already did those things (but you probably weren't able to read it in my first post) and I know C/C++. I never ask for help if I can solve it on my own.

By the way, I prefer Google.

Thank you, anyways.
User avatar
LJS
Greenskin
Posts: 138
Joined: Wed Jan 09, 2013 8:58 pm
x 6

Re: Error LNK2005 and fatal error LNK1169 when debugging

Post by LJS »

Didn't mean to be insultive, my apologies if you took offence. But if you did those; you did find these.

Search query bing.com: LNK2005

only the first five:
MS A LNK2005 error occurs when the CRT library …
MS Linker Tools Error LNK2005
MS LNK2005
MS error LNK2005: __encode_pointer already defined in MSVCRTD ...
SO c++ - error LNK2005: xxx already defined in …

one at Ogre google custom search:
Linker error while using /MT in Visual Studio 2008

If you didn't mix libs, you are propably getting the error because you include a header A in header files B and C, you could resolve it by including header A in the sources of B and C. Then forward declare them in in the headers B and C.

If you know C/C++ already, did you check these: Mad Marx Tutorials
(am very clumbsy, especially with words on a static screen.)
Ogre 3D 1.9.0 static
Bullet 2.8 static
Darkatom
Gnoblar
Posts: 6
Joined: Fri Jul 25, 2014 3:48 am

Re: Error LNK2005 and fatal error LNK1169 when debugging

Post by Darkatom »

I did take it insultive, but if you did not mean to, it's okay.

Yes, I found those. I know there is some header that is being duplicated somewhere, or loaded in the wrong order. Taking a look to the debugging information, (it says OIS_d.lib, (OIS_d.dll)) I checked the propierties and tried to keep the OIS lib out of the debugging as suggested. Would not work, as I expected. I checked every file (both .h and .cpp) and compared them to my main.cpp and ExampleApplication.h (the one I import in main.cpp), commented the includes but still nothing. So I took a look to the .cpp either Visual C++ or the Wizard created (the one with the name of the project, in my case First_OgreApp.cpp) and I saw that the basic structure is the same. It does not call ExampleApplication.h, though. I tried deleting the code (not wanting to destroy the file in case the project crashes beyond repair) and debugging, but still nothing. So I tried copypasting my main.cpp in First_OgreApp.cpp, suspecting that the problem could be having two mains, and deleting the code in main.cpp. Got error LNK1120.

It should not behave this way, that's the biggest problem. It is quite a simple tutorial: Get the wizard, get Visual C++ 2008, get the SDK. Install SDK, Install Wizard, Instal Visual C++, New Project using Wizard, Debug (that was ok), create a main.cpp, debug again (my problem here). Keep going.

I have checked MadMarx's tutorials, yes, but was not sure if it does require a project setup first or if it is using just plain Notepad++ (or Dev-C++, or whatever), so I have them there for further investigation in case I just give up with Visual C++.
User avatar
LJS
Greenskin
Posts: 138
Joined: Wed Jan 09, 2013 8:58 pm
x 6

Re: Error LNK2005 and fatal error LNK1169 when debugging

Post by LJS »

Don't know the version of the app wizard you use so can't say anything about that except if you can upgrade to at least v1.9.0 please do so. v1.10.0 and v2.0 are about here. The tutorials I mentioned go through the structure of Ogre. What is/should be done when and where (and how ofcourse). For me it was easier to follow those then the tutorial framework after I 'learn(ed) c++ first' :wink: . Now I understand the beginners framework too :mrgreen: .

As far as I know you can use any IDE/compiler as long as it is c++, MSVC for sure. You just have to link the proper way, i.e. additional header directories, and the correct libraries (OgreMain_d.lib for the debug and OgreMain.lib for the release), that is it.

When still no solution, feel free to ask. Again my apologies.

R,
(am very clumbsy, especially with words on a static screen.)
Ogre 3D 1.9.0 static
Bullet 2.8 static
Darkatom
Gnoblar
Posts: 6
Joined: Fri Jul 25, 2014 3:48 am

Re: Error LNK2005 and fatal error LNK1169 when debugging

Post by Darkatom »

It's okay, really ^^ I'm sorry I misunderstood you.

So, I took your advice. I uninstalled everything except Visual C++ 2008 and downloaded Ogre 3D SDK v 1.9 for Visual C++ 2008 (32 bit), OgreSDK_vc9_v1-9-0, that is, and the App Wizard Ogre_VC9_Express_AppWizard_1.8.0 and installed them.

I have started a new project, Ogre3DApp this time. Application Type: Standard Application, Application Options: Postbuild Copy.

I get:

Code: Select all

- Ogre3DApp
|- Header Files
||:BaseApplication.h
||:Ogre3DApp.h
||:Resource.h
|
|-Resource Files
||:Ogre3DApp.ico
||:Ogre3DApp.rc
|
|-Source Files
||:BaseApplication.cpp
||:Ogre3DApp.cpp
|
|:ReadMe.txt
That's the project (sorry, could not upload an image).

Tried debugging (did not include a main.cpp nor anything), got two errors.
1>Ogre3DApp.cpp
1>d:\sdks(x86)\ogresdk_vc9_v1-9-0\include\ogre\sdktrays.h(32) : fatal error C1083: Cannot open include file: 'OgreOverlaySystem.h': No such file or directory
1>BaseApplication.cpp
1>d:\sdks(x86)\ogresdk_vc9_v1-9-0\include\ogre\sdktrays.h(32) : fatal error C1083: Cannot open include file: 'OgreOverlaySystem.h': No such file or directory
At least it is not the same, and I think I saw how to fix that somewhere. As soon as I fix this I will post the how, I hope everything's fine after that.
User avatar
LJS
Greenskin
Posts: 138
Joined: Wed Jan 09, 2013 8:58 pm
x 6

Re: Error LNK2005 and fatal error LNK1169 when debugging

Post by LJS »

This is how you set it up:
Setting Up An Application - Visual Studio

Since 1.9.0 the Overlay has been made its own library.

R,
(am very clumbsy, especially with words on a static screen.)
Ogre 3D 1.9.0 static
Bullet 2.8 static
Darkatom
Gnoblar
Posts: 6
Joined: Fri Jul 25, 2014 3:48 am

Re: Error LNK2005 and fatal error LNK1169 when debugging

Post by Darkatom »

Thank you, LJS. I did it, got a new problem, googled it, fixed it looking at Porting Notes here: http://www.ogre3d.org/tikiwiki/tiki-ind ... ting_Notes (remember to put the names of the variables according to the ones of your code, in case someone has the same problem).

Debugged, it worked and a black window appeared (and my mouse pointer in the middle). At least it worked,I don't know if anything else was supposed to happen, but it worked and that's enough for me (for now). Went to the tutorial, created the main.

... Back to the beggining:
1>OIS_d.lib(OIS_d.dll) : error LNK2005: "public: class OIS::MouseState const & __thiscall OIS::Mouse::getMouseState(void)const " (?getMouseState@Mouse@OIS@@QBEABVMouseState@2@XZ) already defined in BaseApplication.obj
1>bin\Debug\Ogre3DApp.exe : fatal error LNK1169: one or more multiply defined symbols found
I learned how Visual C++ redirects you to the location of the error, but it does not find it, so I don't know where else to look. I'll mess around searching for an answer.
User avatar
LJS
Greenskin
Posts: 138
Joined: Wed Jan 09, 2013 8:58 pm
x 6

Re: Error LNK2005 and fatal error LNK1169 when debugging

Post by LJS »

The first turorial of Maddie should be a black window indeed. The second (very short) one too.

Maddies tutorials don't use OIS untill the last one. So it is strange you get the same error. Best is to just follow the tutorial first before doing anything else.

All tutorials are created to get one started and when following those (beginner, intermediate and/or maddies), ogre is out of the box. Do have to admit, forgetting one thing messes all up. Read them carefully.



R,
(am very clumbsy, especially with words on a static screen.)
Ogre 3D 1.9.0 static
Bullet 2.8 static
Post Reply