我正在使用OSG和预先构建的模板项目进行C ++赋值(C ++ 98和VS2010)。我正在尝试使用osgUtil / LineSegementIntersector和osgUtil / IntersectionVisitor类来实现鼠标拾取。不幸的是,当我运行这段代码时,我收到很多LNK2001和LNK2019错误。这两个类位于文件的顶部,带有osg库的文件夹包含在链接器中,而osgUtild.lib文件位于目录中。
代码:
osgViewer::Viewer *pViewer=dynamic_cast<osgViewer::Viewer*>(aa.asView());
osgUtil::LineSegmentIntersector* picker;
picker = new osgUtil::LineSegmentIntersector(osgUtil::Intersector::PROJECTION, ea.getXnormalized(), ea.getYnormalized());
osgUtil::IntersectionVisitor iv(picker);
pViewer->getCamera()->accept(iv);
if(picker->containsIntersections())
{
osgUtil::LineSegmentIntersector::Intersections intersections = picker->getIntersections();
for(osgUtil::LineSegmentIntersector::Intersections::iterator it = intersections.begin(); it != intersections.end(); it++)
{
for(NodePath::const_reverse_iterator rit = it->nodePath.rbegin(); rit != it->nodePath.rend(); rit++)
{
}
}
}
错误:
1>raaOSGSimpleEventHandler.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall osgUtil::IntersectionVisitor::`vbase destructor'(void)" (__imp_??_DIntersectionVisitor@osgUtil@@QAEXXZ) referenced in function "public: virtual bool __thiscall raaOSGSimpleEventHandler::handle(class osgGA::GUIEventAdapter const &,class osgGA::GUIActionAdapter &,class osg::Object *,class osg::NodeVisitor *)" (?handle@raaOSGSimpleEventHandler@@UAE_NABVGUIEventAdapter@osgGA@@AAVGUIActionAdapter@3@PAVObject@osg@@PAVNodeVisitor@6@@Z)
1>raaOSGSimpleEventHandler.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::multiset<struct osgUtil::LineSegmentIntersector::Intersection,struct std::less<struct osgUtil::LineSegmentIntersector::Intersection>,class std::allocator<struct osgUtil::LineSegmentIntersector::Intersection> > & __thiscall osgUtil::LineSegmentIntersector::getIntersections(void)" (__imp_?getIntersections@LineSegmentIntersector@osgUtil@@QAEAAV?$multiset@UIntersection@LineSegmentIntersector@osgUtil@@U?$less@UIntersection@LineSegmentIntersector@osgUtil@@@std@@V?$allocator@UIntersection@LineSegmentIntersector@osgUtil@@@5@@std@@XZ) referenced in function "public: virtual bool __thiscall raaOSGSimpleEventHandler::handle(class osgGA::GUIEventAdapter const &,class osgGA::GUIActionAdapter &,class osg::Object *,class osg::NodeVisitor *)" (?handle@raaOSGSimpleEventHandler@@UAE_NABVGUIEventAdapter@osgGA@@AAVGUIActionAdapter@3@PAVObject@osg@@PAVNodeVisitor@6@@Z)
1>raaOSGSimpleEventHandler.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall osgUtil::IntersectionVisitor::IntersectionVisitor(class osgUtil::Intersector *,struct osgUtil::IntersectionVisitor::ReadCallback *)" (__imp_??0IntersectionVisitor@osgUtil@@QAE@PAVIntersector@1@PAUReadCallback@01@@Z) referenced in function "public: virtual bool __thiscall raaOSGSimpleEventHandler::handle(class osgGA::GUIEventAdapter const &,class osgGA::GUIActionAdapter &,class osg::Object *,class osg::NodeVisitor *)" (?handle@raaOSGSimpleEventHandler@@UAE_NABVGUIEventAdapter@osgGA@@AAVGUIActionAdapter@3@PAVObject@osg@@PAVNodeVisitor@6@@Z)
1>raaOSGSimpleEventHandler.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall osgUtil::LineSegmentIntersector::LineSegmentIntersector(enum osgUtil::Intersector::CoordinateFrame,double,double)" (__imp_??0LineSegmentIntersector@osgUtil@@QAE@W4CoordinateFrame@Intersector@1@NN@Z) referenced in function "public: virtual bool __thiscall raaOSGSimpleEventHandler::handle(class osgGA::GUIEventAdapter const &,class osgGA::GUIActionAdapter &,class osg::Object *,class osg::NodeVisitor *)" (?handle@raaOSGSimpleEventHandler@@UAE_NABVGUIEventAdapter@osgGA@@AAVGUIActionAdapter@3@PAVObject@osg@@PAVNodeVisitor@6@@Z)
1>raaOSGSimpleEventHandler.obj : error LNK2001: unresolved external symbol "public: virtual class osgUtil::Intersector * __thiscall osgUtil::LineSegmentIntersector::clone(class osgUtil::IntersectionVisitor &)" (?clone@LineSegmentIntersector@osgUtil@@UAEPAVIntersector@2@AAVIntersectionVisitor@2@@Z)
1>raaOSGSimpleEventHandler.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall osgUtil::LineSegmentIntersector::enter(class osg::Node const &)" (?enter@LineSegmentIntersector@osgUtil@@UAE_NABVNode@osg@@@Z)
1>raaOSGSimpleEventHandler.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall osgUtil::LineSegmentIntersector::leave(void)" (?leave@LineSegmentIntersector@osgUtil@@UAEXXZ)
1>raaOSGSimpleEventHandler.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall osgUtil::LineSegmentIntersector::intersect(class osgUtil::IntersectionVisitor &,class osg::Drawable *)" (?intersect@LineSegmentIntersector@osgUtil@@UAEXAAVIntersectionVisitor@2@PAVDrawable@osg@@@Z)
1>raaOSGSimpleEventHandler.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall osgUtil::LineSegmentIntersector::reset(void)" (?reset@LineSegmentIntersector@osgUtil@@UAEXXZ)
1>raaOSGSimpleEventHandler.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall osgUtil::LineSegmentIntersector::containsIntersections(void)" (?containsIntersections@LineSegmentIntersector@osgUtil@@UAE_NXZ)
1>raaOSGSimpleEventHandler.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall osgUtil::LineSegmentIntersector::~LineSegmentIntersector(void)" (__imp_??1LineSegmentIntersector@osgUtil@@UAE@XZ) referenced in function "public: virtual void * __thiscall osgUtil::LineSegmentIntersector::`scalar deleting destructor'(unsigned int)" (??_GLineSegmentIntersector@osgUtil@@UAEPAXI@Z)
1>D:\raaOSG(1)\raaOSG\raaOSGResource\Debug\raaOSGSimpleDemoD.exe : fatal error LNK1120: 11 unresolved externals
我看不到我的代码或设置有什么问题,基于我所阅读的一切,我目前的唯一想法是osgUtil库未包含某些内容(某个地方的dll或类似文件),但我无法看看我将如何解决。
任何和所有建议都将不胜感激-尽管我肯定会很快入睡,所以我可能不会立即回应。
最佳答案
编译时不包含Dll。仅指定文件夹是不够的。您需要指定要显式使用OsgUtild.lib链接器。
关于c++ - 打开场景图LNK2019错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23667772/