Chinaunix首页 | 论坛 | 博客
  • 博客访问: 331305
  • 博文数量: 29
  • 博客积分: 5710
  • 博客等级: 大校
  • 技术积分: 567
  • 用 户 组: 普通用户
  • 注册时间: 2006-09-18 11:52
文章分类

全部博文(29)

文章存档

2011年(2)

2010年(9)

2009年(6)

2008年(12)

我的朋友

分类: WINDOWS

2008-06-02 14:31:30

编译jrtplib程序问题总结(菜鸟帖)

                                      

首先要保证编译通过。如果编译通不过,多半是由于没有加载需要的头文件。然后是链接。这时会有很多问题出现。

一、最开始出现的问题
   
    example2.obj : error LNK2019: 无法解析的外部符号 "public: virtual __thiscall RTPSession::~RTPSession(void)" (??1RTPSession@@UAE@XZ) ,该符号在函数 _main 中被引用
example2.obj : error LNK2019: 无法解析的外部符号 __imp__WSACleanup@0 ,该符号在函数 _main 中被引用
example2.obj : error LNK2019: 无法解析的外部符号 "public: void __thiscall RTPSession::BYEDestroy(class RTPTime const &,void const *,unsigned int)" (?BYEDestroy@RTPSession@@QAEXABVRTPTime@@PBXI@Z) ,该符号在函数 _main 中被引用
example2.obj : error LNK2019: 无法解析的外部符号 "public: int __thiscall RTPSession::EndDataAccess(void)" (?EndDataAccess@RTPSession@@QAEHXZ) ,该符号在函数 _main 中被引用
很明显,是关于类RTPSession的问题,问题出在缺少lib库jrtplib.lib。
   
    是由于没有找到lib库,也就是链接设置中没有设置所需要的lib。解决:
    可以在.h或者cpp中添加代码:
   
    #pragma comment (lib, "jrtplib.lib")
    #pragma comment (lib, "jthread.lib")
    也可以在“链接器”中“附加依赖项”中添加这些库。


二、解决了第一个问题之后,重新链接。发现问题增多了,出现了大量类似的问题,好几百个。如下:
   
    msvcprtd.lib(MSVCP71D.dll) : error LNK2005: "public: __thiscall std::basic_string,class std::allocator >::~basic_string,class std::allocator >(void)" (??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ) 已经在 example2.obj 中定义
msvcprtd.lib(MSVCP71D.dll) : error LNK2005: "public: __thiscall std::basic_string,class std::allocator >::basic_string,class std::allocator >(char const *)" (??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z) 已经在 example2.obj 中定义
msvcprtd.lib(MSVCP71D.dll) : error LNK2005: "public: __thiscall std::basic_string,class std::allocator >::basic_string,class std::allocator >(class
   
     问题增多,并不是说问题一的解决方法错误。恰恰是因为解决了问题一,才使得其他问题暴露出来。
     解决方法:设置VC运行库(C/C++->CodeGeneration->Use Runtime library 选MultiThreaded DLL
     在网上搜索了好半天才找到的解决方法。当然,之所以费了时间,使因为自己没有认真看buildblog,再次提醒大家注意观察    buildblog里面的提示。
     这个问题的原因是什么呢?
     一句话:因为运行时库的版本问题。VC编译器的运行时库有多个选项:/ML、/MLd、/MT、/MTd、/MD、/MDd。这些选项告诉编译器应用程序想使用什么版本的C标准程序库。这样会在运行时选择不同版本的库。
    在编译JrtpLIB库时,我选择了“多线程调试/MDd”,而在编译应用程序中选择了不同的选项,这样导致了运行库的不一致。最终出错。

三、前两个问题解决了,这时候编译的话,还是有问题的。如下:

example2.obj : error LNK2019: 无法解析的外部符号__imp__WSACleanup@0 ,该符号在函数 _main 中被引用
example2.obj : error LNK2019: 无法解析的外部符号 __imp__WSAStartup@8 ,该符号在函数 _main 中被引用
jrtplib.lib(rtpsession.obj) : error LNK2019: 无法解析的外部符号 __imp__gethostname@8 ,该符号在函数 "private: int __thiscall RTPSession::CreateCNAME(unsigned char *,unsigned int *,bool)" (?CreateCNAME@RTPSession@@AAEHPAEPAI_N@Z) 中被引用
jrtplib.lib(rtpudpv4transmitter.obj) : ················

    从这些错误中明显可以看出都是socket函数,所以可以分析出时因为缺少了相应的lib。当然,具体是哪个lib呢?如果熟悉代码使用的相关库的话,一眼就看得出来。如果不行就用msdn或者上网找。ws2_32.lib!!!!
    解决方法:#pragma comment (lib, "ws2_32.lib")
   
    搞定!

阅读(2485) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~