查看: 1576|回复: 6

初学者紧急救助!!!!!

[复制链接]

该用户从未签到

发表于 2010-12-2 23:39:29 | 显示全部楼层 |阅读模式
目前正在学习OSG,手头的两本教材就是FreeSouth的《OpenSceneGraph设计教程》和Array的《OpenSceneGraph三维渲染引擎设计与指南》,但一上手就遇到了几个问题,下面分别把代码考上来并有附件,希望得到大侠的指导,因为这几个问题已经困扰了我10天了,有点崩溃!

// 下面的这个例子是FreeSouth书中的第五个例子:
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osg/Node>
void main()
{
osgViewer::Viewer viewer;
osg::Group * root = new osg::Group();
root->addChild(osgDB::readNodeFile("lider.osg"));
root->addChild(osgDB::readNodeFile("osgcool.osg"));
viewer.setSceneData(root);
viewer.realize();
viewer.run();
}

结果,编译通过,但是运行时程序出现异常Unhandled exception at 0x7c812afb in Example5.exe: Microsoft C++ exception: __non_rtti_object @ 0x0012fac0.程序停在了dHeap.c中的这个函数出:

_CRTIMP void * __cdecl malloc (
        size_t nSize
        )
{
        void *res = _nh_malloc_dbg(nSize, _newmode, _NORMAL_BLOCK, NULL, 0);
        RTCCALLBACK(_RTC_Allocate_hook, (res, nSize, 0));
        return res;
}

// 下面的这个例子是Array书中的第二个例子:
#include <osg/Node>
#include <osgDB/ReadFile>
#include <iostream>

class InfoVisitor : public osg::NodeVisitor
{
public:
InfoVisitor()sg::NodeVisitor(TRAVERSE_ALL_CHILDREN), _indent(0){}
virtual void apply(osg::Node& node)
{
  for(int i = 0; i < _indent; i++)
   std::cout << " ";
  std::cout << "[" <<  _indent << "]" << node.libraryName() << "::" << node.className() << std::endl;
  _indent++;
  traverse(node);
  _indent--;
}
virtual void apply(osg::Geode& node)
{
  for(int i = 0; i < _indent; i++)
   std::cout << " ";
  std::cout << "[" << _indent << "]" << node.libraryName() << "::" << node.className() << std::endl;
  for(unsigned int n = 0; n < node.getNumDrawables(); ++n)
  {
   osg:rawable* drawable = node.getDrawable(n);
   if(!drawable)
    continue;
   for(int i = 0; i <= _indent; i++)
    std::cout << " ";
   std::cout << drawable->libraryName() << "::" << drawable->className() << std::endl;
  }
  _indent++;
  traverse(node);
  _indent--;
}
protected:
int _indent;
};

void main(int argc, char**argv)
{
osg::ArgumentParser arguments(&argc, argv);
osg::Node* root = osgDB::readNodeFiles(arguments);
if(!root)
  root = osgDB::readNodeFile("axes.osg");
InfoVisitor infoVisitor;
if(root)
  root->accept(infoVisitor);
}

结果,编译通过,运行时出现下面的链接错误
Example3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::operator<<(class std::basic_ostream<char,struct std::char_traits<char> > & (__cdecl*)(class std::basic_ostream<char,struct std::char_traits<char> > &))" ([email=__imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@P6AAAV01@AAV01@@Z@Z]__imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@P6AAAV01@AAV01@@Z@Z[/email]) referenced in function "public: virtual void __thiscall InfoVisitor::apply(class osg::Node &)" ([email=?apply@InfoVisitor@@UAEXAAVNode@osg@@@Z]?apply@InfoVisitor@@UAEXAAVNode@osg@@@Z[/email])
Example3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::operator<<(int)" ([email=__imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@H@Z]__imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@H@Z[/email]) referenced in function "public: virtual void __thiscall InfoVisitor::apply(class osg::Node &)" ([email=?apply@InfoVisitor@@UAEXAAVNode@osg@@@Z]?apply@InfoVisitor@@UAEXAAVNode@osg@@@Z[/email])
Example3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::flush(void)" ([email=__imp_?flush@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV12@XZ]__imp_?flush@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV12@XZ[/email]) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::endl(class std::basic_ostream<char,struct std::char_traits<char> > &)" ([email=?endl@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@1@AAV21@@Z]?endl@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@1@AAV21@@Z[/email])
Example3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::put(char)" ([email=__imp_?put@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV12@D@Z]__imp_?put@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV12@D@Z[/email]) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::endl(class std::basic_ostream<char,struct std::char_traits<char> > &)" ([email=?endl@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@1@AAV21@@Z]?endl@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@1@AAV21@@Z[/email])
Example3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_streambuf<char,struct std::char_traits<char> > * __thiscall std::basic_ios<char,struct std::char_traits<char> >::rdbuf(void)const " ([email=__imp_?rdbuf@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?$basic_streambuf@DU?$char_traits@D@std@@@2@XZ]__imp_?rdbuf@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?$basic_streambuf@DU?$char_traits@D@std@@@2@XZ[/email]) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" ([email=??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z]??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z[/email])
Example3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: char __thiscall std::basic_ios<char,struct std::char_traits<char> >::fill(void)const " ([email=__imp_?fill@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEDXZ]__imp_?fill@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEDXZ[/email]) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" ([email=??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z]??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z[/email])
Example3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_ostream<char,struct std::char_traits<char> > * __thiscall std::basic_ios<char,struct std::char_traits<char> >::tie(void)const " ([email=__imp_?tie@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?$basic_ostream@DU?$char_traits@D@std@@@2@XZ]__imp_?tie@?$basic_ios@DU?$char_traits@D@std@@@std@@QBEPAV?$basic_ostream@DU?$char_traits@D@std@@@2@XZ[/email]) referenced in function "public: __thiscall std::basic_ostream<char,struct std::char_traits<char> >::sentry::sentry(class std::basic_ostream<char,struct std::char_traits<char> > &)" ([email=??0sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@AAV12@@Z]??0sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@AAV12@@Z[/email])
Example3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::basic_ostream<char,struct std::char_traits<char> >::_Osfx(void)" ([email=__imp_?_Osfx@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEXXZ]__imp_?_Osfx@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEXXZ[/email]) referenced in function "public: __thiscall std::basic_ostream<char,struct std::char_traits<char> >::sentry::~sentry(void)" ([email=??1sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@XZ]??1sentry@?$basic_ostream@DU?$char_traits@D@std@@@std@@QAE@XZ[/email])
Debug/Example3.exe : fatal error LNK1120: 8 unresolved externals
Build log was saved at "file://e:\OpenSceneGraph\osg-practice\Array\Example3\Debug\BuildLog.htm"
Example3 - 9 error(s), 72 warning(s)

肯定得到大侠的指点,不胜感激!

该用户从未签到

发表于 2010-12-3 08:18:48 | 显示全部楼层
您需要给出自己的工程配置,以及所用的OSG库的版本和编译方法等信息。可以肯定这是您的工程配置的问题,将工程(不需要中间文件!)直接粘帖附件也是可以的

该用户从未签到

发表于 2010-12-3 10:00:54 | 显示全部楼层
对的,osg版本,编译器,库配置都得正确才行

该用户从未签到

 楼主| 发表于 2010-12-4 17:56:50 | 显示全部楼层
我用的是VS .NET 2003,编译的是0SG-2.8.0,采用的第三方库直接采用TortoiseSVN下载了3rdParty_win32binaries_vs71,编译后的例子都可以运行,除了极个别的出现“could not find plugins to read the file arial.acx”之外都可以正常运行。下面我把我的上面列出的那2个例子传上来,请高手帮我看看问题出在了哪里 Example3.rar (2.05 MB, 下载次数: 74)

该用户从未签到

发表于 2010-12-5 01:31:57 | 显示全部楼层
example3试了下
在 属性页/cc++/代码生成/运行时库  -  多线程调试DLL
属性页/cc++/语言/启用运行时类型信息 - 是
这通过了

该用户从未签到

发表于 2010-12-5 10:14:40 | 显示全部楼层
1清理一下项目,项目右键-〉清理文件;
2重新生成

如果还不行的话,用depends(ms用来查看文件dll依赖的一个小工具)看看哪个dll没找到。

该用户从未签到

 楼主| 发表于 2010-12-5 14:28:32 | 显示全部楼层
example3试了下
在 属性页/cc++/代码生成/运行时库  -  多线程调试DLL
属性页/cc++/语言/启用运行时类型信息 - 是
这通过了
myhere123 发表于 2010-12-5 01:31


刚试过你的方法,也是Array说的工程配置的问题,修改过后,程序运行通过,十分感谢!!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表