Ogre 3D error - LNK1120: 1 unresolved externals

632 Views Asked by At

I have come to second Ogre tutorial on Ogre wiki, renamed the files as prompted by the tutorial and replaced the code, but I get this error:

    1>------ Build started: Project: Flight Simulator, Configuration: Debug Win32 ------
    1>BaseApplication.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to        '/INCREMENTAL:NO' specification
    1>MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
    1>C:\Users\Jura\Documents\Visual Studio 2010\Projects\Flight Simulator\Debug\Flight Simulator.exe : fatal error LNK1120: 1 unresolved externals
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

I already googled, but I didn't seem to find the answer.

This is code from BasicTutorial2.cpp:

#include "BasicTutorial2.h"

//-------------------------------------------------------------------------------------
BasicTutorial2::BasicTutorial2(void)
{
}


//-------------------------------------------------------------------------------------
BasicTutorial2::~BasicTutorial2(void)
{
}

//-------------------------------------------------------------------------------------
void BasicTutorial2::createCamera(void)
{
}

//-------------------------------------------------------------------------------------
void BasicTutorial2::createViewports(void)
{
}

//-------------------------------------------------------------------------------------
void BasicTutorial2::createScene(void)
{
}

This is in my BasicTutorial2.h file:

/*
-----------------------------------------------------------------------------
Filename:    BasicTutorial2.h
-----------------------------------------------------------------------------

This source file is part of the
   ___                 __    __ _ _    _ 
  /___\__ _ _ __ ___  / / /\ \ (_) | _(_)
 //  // _` | '__/ _ \ \ \/  \/ / | |/ / |
/ \_// (_| | | |  __/  \  /\  /| |   <| |
\___/ \__, |_|  \___|   \/  \/ |_|_|\_\_|
      |___/                              
      Tutorial Framework
      http://www.ogre3d.org/tikiwiki/
-----------------------------------------------------------------------------
*/
#ifndef __BasicTutorial2_h_
#define __BasicTutorial2_h_

#include "BaseApplication.h"

class BasicTutorial2 : public BaseApplication
{
public:
    BasicTutorial2(void);
    virtual ~BasicTutorial2(void);

protected:
    virtual void createScene(void);
    virtual void createCamera(void);
    virtual void createViewports(void);
};

#endif // #ifndef __BasicTutorial2_h_

In the directory, I also have BaseApplication.cpp and stdafx.cpp and of course their header files (BaseApplication.h and stdafx.h).

So, this is my directory structure:

Header files  
   stdafx.h;
   BaseApplication.h;
   BasicTutorial2.h;

Source files
   stdafx.cpp;
   BaseApplication.cpp;
   BasicTutorial2.cpp;

I hope someone will give me the solution. I tried changing the subsystem from "Windows" to "Console", but no luck. I also tried other solutions, but also no luck.

1

There are 1 best solutions below

0
On

Answer: I forgot to add the main (win) function to the BasicTutorial2.cpp:

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
    INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
    int main(int argc, char *argv[])
#endif
    {
        // Create application object
        BasicTutorial2 app;

        try {
            app.go();
        } catch( Ogre::Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
            MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
            std::cerr << "An exception has occured: " <<
                e.getFullDescription().c_str() << std::endl;
#endif
        }

        return 0;
    }

#ifdef __cplusplus
}
#endif

So, BasicTutorial2.cpp looks like this in the end :

#include "BasicTutorial2.h"

//-------------------------------------------------------------------------------------
BasicTutorial2::BasicTutorial2(void)
{
}


//-------------------------------------------------------------------------------------
BasicTutorial2::~BasicTutorial2(void)
{
}

//-------------------------------------------------------------------------------------
void BasicTutorial2::createCamera(void)
{
}

//-------------------------------------------------------------------------------------
void BasicTutorial2::createViewports(void)
{
}

//-------------------------------------------------------------------------------------
void BasicTutorial2::createScene(void)
{
}

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
    INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
    int main(int argc, char *argv[])
#endif
    {
        // Create application object
        BasicTutorial2 app;

        try {
            app.go();
        } catch( Ogre::Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
            MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
            std::cerr << "An exception has occured: " <<
                e.getFullDescription().c_str() << std::endl;
#endif
        }

        return 0;
    }

#ifdef __cplusplus
}
#endif

So, for other tutorials, just change the names accordingly. Search for BasicTutorial2 and replace it e.g. with BasicTutorial3 and rename the files and never remove the main() function, since it will cause a lot of unnecessary headaches.