【问题标题】:Ogre 3D error - LNK1120: 1 unresolved externalsOgre 3D 错误 - LNK1120: 1 未解决的外部
【发布时间】:2013-07-16 10:49:13
【问题描述】:

我来到了Ogre wiki上的second Ogre tutorial,按照教程的提示重命名了文件并替换了代码,但是我得到了这个错误:

    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 ==========

我已经用谷歌搜索了,但我似乎没有找到答案。

这是来自BasicTutorial2.cpp的代码:

#include "BasicTutorial2.h"

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


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

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

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

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

这是在我的BasicTutorial2.h 文件中:

/*
-----------------------------------------------------------------------------
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_

在目录中,我还有BaseApplication.cppstdafx.cpp,当然还有它们的头文件(BaseApplication.hstdafx.h)。

所以,这是我的目录结构:

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

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

我希望有人能给我解决方案。我尝试将子系统从“Windows”更改为“控制台”,但没有运气。我也尝试了其他解决方案,但也没有运气。

【问题讨论】:

  • 你的(win)主要功能在哪里?

标签: c++ ogre 3d-engine visual-studio-2010


【解决方案1】:

回答:我忘记在 BasicTutorial2.cpp 中添加 main(win)函数:

#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

所以,BasicTutorial2.cpp 最终看起来像这样:

#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

因此,对于其他教程,只需相应地更改名称即可。搜索 BasicTutorial2 并替换它,例如使用 BasicTutorial3 并重命名文件并且永远不要删除 main() 函数,因为它会引起很多不必要的麻烦。

【讨论】:

    猜你喜欢
    • 2015-01-11
    • 1970-01-01
    • 2012-06-03
    • 2022-01-05
    • 2011-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多