I need to integrate Ogre 3d in Qt 4. I found several codes and suggestions which are unfortunately out-dated. I liked this tutorial
http://irmatden.developpez.com/tutoriels/qt/integration-ogre-qt/
It works with Ogre 1.4.9 (Eihorn) but not with the recent version 1.7.0. Compiling the app with the recent one results in a linker error
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*)' o开发者_JS百科grewidget.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
What might cause this and how do I solve it?
The memory allocator of your OgreBuildSettings.h
probably doesn't reflect the one Ogre was actually built with. Change it to the one used when you built Ogre (or just play with the numbers of #define OGRE_MEMORY_ALLOCATOR
. It happens when you update Ogre and forget to replace OgreBuildSettings.h
in an alternative include path (maybe your project's).
An Example using QT4 and Ogre Eihort http://www.ogre3d.org/tikiwiki/QtOgre
In ogrewidget.cpp just replace....
// 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!
With....
// 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;
And it works with Ogre 1.7.3
To use...
OgreWidget *ogreWidget = new OgreWidget();
精彩评论