首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

linux编译RTP的有关问题

2012-12-29 
linux编译RTP的问题在网上下载了一个rtp的测试程式。但编译出现问题,不知道怎么回事? #include stdio.h#i

linux编译RTP的问题
在网上下载了一个rtp的测试程式。但编译出现问题,不知道怎么回事?

 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>

#include <stdlib.h>

#include "rtpsession.h"
#include "rtppacket.h"
using namespace std;
// 错误处理函数
void checkerror(int err)
{
  if (err < 0) {
    char* errstr = RTPGetErrorString(err);
    printf("Error:%s\\n", errstr);
    exit(-1);
  }
}

int main(int argc, char** argv)
{
  RTPSession sess;
  int localport;
  int status;
  int timestamp,lengh = 1025,length = 0;
  char buffer[32768];
  unsigned char *RawData;
  
  if (argc != 2) {
    printf("Usage: ./recieve localport\\n");
    return -1;
  }

   // 获得用户指定的端口号
  localport = atoi(argv[1]);

  // 创建RTP会话
  status = sess.Create(localport);
  checkerror(status);
  FILE *file = 0; 
  int i = 0;
  int j = 1;
        

  do {
    // 接受RTP数据
    status = sess.PollData();
 // 检索RTP数据源

    if (sess.GotoFirstSourceWithData())
    {

      do {
        RTPPacket* packet;
        // 获取RTP数据报
        
        while ((packet = sess.GetNextPacket()) != NULL) {
        
           printf("Got packet %d! of pic %d!\n",i,j);
      timestamp = packet->GetTimeStamp();
           lengh=packet->GetPayloadLength();
           length += lengh;
           RawData=packet->GetPayload();   //得到实际有效数据
           printf(" timestamp:%d;lengh=%d\n",timestamp,lengh);
           memcpy(&buffer[1024*i],RawData,lengh); 
           i ++;    
            delete packet;
          // 删除RTP数据报
        }
      } while (sess.GotoNextSourceWithData());
    }    
    if(lengh < 1024)
    {
        if((file = fopen("rtp_rev.jpg", "wb")) < 0)


    {
           printf("Unable to create y frame recording file\n");
            return -1;
    }
    else
    {
    fwrite(buffer, length, 1, file);
    printf("buffer write %d bytes into file.\n",length);
    fclose(file);
    i = 0;//write over so reset i
    j ++ ;//write pic and j++
    lengh = 1025;
    }
    }  
  } while(1);

  return 0;
}



编译信息如下:
acer@ubuntu:~/v4l2_jpeg_rtp$ make
sudo g++ -o jpegrtp_reciever jpegrtp_recieve.c  -I /home/acer/jrtplib-2.9/share/include/jrtplib/ -L /home/acer/jrtplib-2.9/share/lib/libjrtp.a \
                                    -L /home/acer/jrtplib-2.9/share/lib/libSDL.a -L /home/acer/jrtplib-2.9/share/lib/libSDL_image.a 
/tmp/ccEbgatJ.o: In function `checkerror(int)':
jpegrtp_recieve.c:(.text+0x13): undefined reference to `RTPGetErrorString(int)'
/tmp/ccEbgatJ.o: In function `main':
jpegrtp_recieve.c:(.text+0x67): undefined reference to `RTPSession::RTPSession()'
jpegrtp_recieve.c:(.text+0xc4): undefined reference to `RTPSession::Create(int, unsigned long)'
jpegrtp_recieve.c:(.text+0xfb): undefined reference to `RTPSession::PollData()'
jpegrtp_recieve.c:(.text+0x1c7): undefined reference to `RTPPacket::~RTPPacket()'
jpegrtp_recieve.c:(.text+0x2b2): undefined reference to `RTPSession::~RTPSession()'
jpegrtp_recieve.c:(.text+0x2ca): undefined reference to `RTPSession::~RTPSession()'
/tmp/ccEbgatJ.o: In function `RTPSession::GotoFirstSourceWithData()':
jpegrtp_recieve.c:(.text._ZN10RTPSession23GotoFirstSourceWithDataEv[RTPSession::GotoFirstSourceWithData()]+0x2a): undefined reference to `RTPSources::GotoFirstSourceWithData()'
/tmp/ccEbgatJ.o: In function `RTPSession::GotoNextSourceWithData()':
jpegrtp_recieve.c:(.text._ZN10RTPSession22GotoNextSourceWithDataEv[RTPSession::GotoNextSourceWithData()]+0x2a): undefined reference to `RTPSources::GotoNextSourceWithData()'
/tmp/ccEbgatJ.o: In function `RTPSession::GetNextPacket()':
jpegrtp_recieve.c:(.text._ZN10RTPSession13GetNextPacketEv[RTPSession::GetNextPacket()]+0x4a): undefined reference to `RTPSourceData::ExtractPacket()'
collect2: ld returned 1 exit status
make: *** [all] 错误 1

[解决办法]
-L只是指定路径,还需要-l
这样:
-L /home/acer/jrtplib-2.9/share/lib/ -l jrtp \
  -L /home/acer/jrtplib-2.9/share/lib -l SDL -L /home/acer/jrtplib-2.9/share/lib/ -l SDL_image

热点排行