在Qt中集成OGRE 1.7

时间:2010-03-03 11:37:38

标签: qt qt4 ogre3d ogre

我需要在Qt 4中集成Ogre 3d。我发现了几个不幸过时的代码和建议。我喜欢这个教程

http://irmatden.developpez.com/tutoriels/qt/integration-ogre-qt/

它适用于Ogre 1.4.9(Eihorn),但不适用于最新版本1.7.0。使用最近的应用程序编译应用程序会导致链接器错误

ogrewidget.o: In function `OgreWidget::~OgreWidget()':
ogrewidget.cpp:(.text+0x5b6): undefined reference to `Ogre::NedPoolingImpl::deallocBytes(void*)'
ogrewidget.o: In function `OgreWidget::~OgreWidget()':
ogrewidget.cpp:(.text+0x666): undefined reference to `Ogre::NedPoolingImpl::deallocBytes(void*)'
ogrewidget.o: In function `OgreWidget::~OgreWidget()':
ogrewidget.cpp:(.text+0x6f6): undefined reference to `Ogre::NedPoolingImpl::deallocBytes(void*)'
ogrewidget.o: In function `OgreWidget::initOgreSystem()':
ogrewidget.cpp:(.text+0x1cfb): undefined reference to `Ogre::NedPoolingImpl::allocBytes(unsigned int, char const*, int, char const*)'
ogrewidget.cpp:(.text+0x1dde): undefined reference to `Ogre::Root::initialise(bool, std::basic_string, std::allocator > const&, std::basic_string, std::allocator > const&)'
ogrewidget.cpp:(.text+0x2278): undefined reference to `Ogre::Root::createRenderWindow(std::basic_string, std::allocator > const&, unsigned int, unsigned int, bool, std::map, std::allocator >, std::basic_string, std::allocator >, std::less, std::allocator > >, Ogre::STLAllocator, std::allocator > const, std::basic_string, std::allocator > >, Ogre::CategorisedAllocPolicy > > const*)'
ogrewidget.cpp:(.text+0x2c31): undefined reference to `Ogre::NedPoolingImpl::deallocBytes(void*)'
ogrewidget.o: In function `std::_Rb_tree, std::allocator >, std::pair, std::allocator > const, std::basic_string, std::allocator > >, std::_Select1st, std::allocator > const, std::basic_string, std::allocator > > >, std::less, std::allocator > >, Ogre::STLAllocator, std::allocator > const, std::basic_string, std::allocator > >, Ogre::CategorisedAllocPolicy > >::_M_insert_(std::_Rb_tree_node_base const*, std::_Rb_tree_node_base const*, std::pair, std::allocator > const, std::basic_string, std::allocator > > const&)':
ogrewidget.cpp:(.text._ZNSt8_Rb_treeISsSt4pairIKSsSsESt10_Select1stIS2_ESt4lessISsEN4Ogre12STLAllocatorIS2_NS7_22CategorisedAllocPolicyILNS7_14MemoryCategoryE0EEEEEE10_M_insert_EPKSt18_Rb_tree_node_baseSG_RKS2_[std::_Rb_tree, std::allocator >, std::pair, std::allocator > const, std::basic_string, std::allocator > >, std::_Select1st, std::allocator > const, std::basic_string, std::allocator > > >, std::less, std::allocator > >, Ogre::STLAllocator, std::allocator > const, std::basic_string, std::allocator > >, Ogre::CategorisedAllocPolicy > >::_M_insert_(std::_Rb_tree_node_base const*, std::_Rb_tree_node_base const*, std::pair, std::allocator > const, std::basic_string, std::allocator > > const&)]+0x40): undefined reference to `Ogre::NedPoolingImpl::allocBytes(unsigned int, char const*, int, char const*)'
ogrewidget.cpp:(.text._ZNSt8_Rb_treeISsSt4pairIKSsSsESt10_Select1stIS2_ESt4lessISsEN4Ogre12STLAllocatorIS2_NS7_22CategorisedAllocPolicyILNS7_14MemoryCategoryE0EEEEEE10_M_insert_EPKSt18_Rb_tree_node_baseSG_RKS2_[std::_Rb_tree, std::allocator >, std::pair, std::allocator > const, std::basic_string, std::allocator > >, std::_Select1st, std::allocator > const, std::basic_string, std::allocator > > >, std::less, std::allocator > >, Ogre::STLAllocator, std::allocator > const, std::basic_string, std::allocator > >, Ogre::CategorisedAllocPolicy > >::_M_insert_(std::_Rb_tree_node_base const*, std::_Rb_tree_node_base const*, std::pair, std::allocator > const, std::basic_string, std::allocator > > const&)]+0x10d): undefined reference to `Ogre::NedPoolingImpl::deallocBytes(void*)'
ogrewidget.o: In function `std::_Rb_tree, std::allocator >, std::pair, std::allocator > const, std::basic_string, std::allocator > >, std::_Select1st, std::allocator > const, std::basic_string, std::allocator > > >, std::less, std::allocator > >, Ogre::STLAllocator, std::allocator > const, std::basic_string, std::allocator > >, Ogre::CategorisedAllocPolicy > >::_M_erase(std::_Rb_tree_node, std::allocator > const, std::basic_string, std::allocator > > >*)':
ogrewidget.cpp:(.text._ZNSt8_Rb_treeISsSt4pairIKSsSsESt10_Select1stIS2_ESt4lessISsEN4Ogre12STLAllocatorIS2_NS7_22CategorisedAllocPolicyILNS7_14MemoryCategoryE0EEEEEE8_M_eraseEPSt13_Rb_tree_nodeIS2_E[std::_Rb_tree, std::allocator >, std::pair, std::allocator > const, std::basic_string, std::allocator > >, std::_Select1st, std::allocator > const, std::basic_string, std::allocator > > >, std::less, std::allocator > >, Ogre::STLAllocator, std::allocator > const, std::basic_string, std::allocator > >, Ogre::CategorisedAllocPolicy > >::_M_erase(std::_Rb_tree_node, std::allocator > const, std::basic_string, std::allocator > > >*)]+0x47): undefined reference to `Ogre::NedPoolingImpl::deallocBytes(void*)'
collect2: ld returned 1

可能导致此问题的原因以及如何解决?

2 个答案:

答案 0 :(得分:3)

OgreBuildSettings.h的内存分配器可能并不反映实际构建的Ogre。将它更改为您构建Ogre时使用的那个(或者只使用#define OGRE_MEMORY_ALLOCATOR的数字。当您更新Ogre并忘记在替代包含路径(可能是您的项目)中替换OgreBuildSettings.h时,会发生这种情况。

答案 1 :(得分:1)

使用QT4和Ogre Eihort的示例 http://www.ogre3d.org/tikiwiki/QtOgre

在ogrewidget.cpp中只需替换....

  // setup a renderer
  Ogre::RenderSystemList *renderers = mOgreRoot->getAvailableRenderers();
  assert( !renderers->empty() ); // we need at least one renderer to do anything useful

  Ogre::RenderSystem *renderSystem;
  renderSystem = chooseRenderer( renderers );

  assert( renderSystem ); // user might pass back a null renderer, which would be bad!

使用....

  // setup a renderer
  Ogre::RenderSystemList::const_iterator renderers = mOgreRoot->getAvailableRenderers().begin();
  while(renderers != mOgreRoot->getAvailableRenderers().end())
  {
      Ogre::String rName = (*renderers)->getName();
        if (rName == "OpenGL Rendering Subsystem")
            break;
        renderers++;
  }

  Ogre::RenderSystem *renderSystem = *renderers;

它适用于Ogre 1.7.3

使用......

OgreWidget * ogreWidget = new OgreWidget();