(轉)ubuntu下jthread 和jrtplib的安裝

來源:互聯網
上載者:User

標籤:

ubuntu12.04

1.       下載開發包解壓。分別下載jrtplib-3.7.1.tar.gz和jthread-1.2.1.tar.gz。為:

http://research.edm.uhasselt.be/jori/jrtplib/jrtplib-3.7.1.tar.gz和

http://research.edm.uhasselt.be/jori/jthread/jthread-1.2.1.tar.gz

2.       將源檔案放到如下任意目錄中,這裡假設放到主目錄下:/home/jrtplib/。分別解壓#tar -xzvf xxx,xxx為檔案名稱。解壓後出現兩個目錄,一個是jrtplib-3.7.1,一個是jthread-1.2.1。然後進行安裝,先安裝jthread,再安裝jrtplib,這裡邊保證安裝的順序為先安裝jthread,在安裝 jrtplib。

3.       jthread安裝:進入jthead解壓目錄,首先,運行#./configure配置環境,產生makefile檔案,如果出現permission denied,說明我們需要給檔案configure執行的許可權,運行#chmod a+x configure即可。配置好環境後,運行#make。make成功後,再運行#make install。安裝成功以後會在/urs/local/include目錄下多出一個檔案夾jthread。

4.       jrtplib安裝同上,全部安裝好以後會在/urs/local/include目錄下多出兩個檔案夾jrtplib3(可能由於版本不同,產生的檔案夾名字略有不同,比如叫jrtplib-3.7.1)和jthead。複製jthead下所有檔案(都是尾碼為.h的標頭檔)到jrtplib檔案夾下,目的是為了讓所有標頭檔在一個目錄下方便調用。

5.       裝好以後系統內容如下,靜態動態庫安裝到了/usr/local/lib目錄下,包括libjrtplib-3.7.1.so和libjthread-1.2.1.so等。標頭檔在/usr/local/include/jrtplib-3.7.1目錄下。

6.       在jrtplib原始碼目錄裡有樣本程式,在目錄example下,實驗一下編譯example1.cpp,使用靜態庫libjrtp.a連結,編譯連結語句如下(注意用g++而不是gcc編譯,因為是連結階段需要g++):
g++ -o example1 example1.cpp -I /usr/local/include/jrtplib/ -ljrtp
即產生應用程式exmaple1,注意,-I(大寫的i)參數中路徑為jrtplib標頭檔目錄,根據實際情況修改。如果出現錯誤,說明動態連結程式庫路徑不對,有以下兩種方法可以對動態連結程式庫的路徑進行設定:

a、修改動態連結程式庫宏LD_LIBRARY_PATH。LD_LIBRARY_PATH 這個環境變數是大家最為熟悉的,它告訴loader:在哪些目錄中可以找到共用庫。可以設定多個搜尋目錄,這些目錄之間用冒號分隔開。export LD_LIBRARY_PATH=/usr/local/lib,然後再運行編譯,即可通過。這種方法只是暫時修改路徑,在重啟shell後會失效。或者是配置在環境變數檔案/etc/profile中,重啟或者source /etc/profile 生效,source 只在本控制台生效。

b、永久生效的方法為修改動態連結程式庫設定檔/etc/ld.so.conf,或者在/etc/ld.so.conf.d裡建立一個新檔案,並把需要的目錄加到這個檔案裡。具體方法如下:(說明:這種修改動態連結程式庫配置的方式需要使用超級使用者權限,不然沒有對共用庫設定檔的寫入權限)

#cd /etc/ld.so.conf.d

#vim jrtplib在編輯環境下加入/usr/local/lib,儲存退出。

#ldconfig 重新載入動態連結程式庫。

然後再執行編譯連結,成功產生example1檔案。

 

然後運行./example1。成功。

 

 

關於 jrtp 的一些說明:

說明 1 : jrtp 有兩種資料接收方式:第一種是用 jthread 庫提供的線程自動在後台執行對資料的接收。第二種是使用者自己調用 RTPSession 中的 Poll 方法。如果採取第一種方法則要安裝 jthread 庫,則安裝 jthread-1.2.1.tar.gz ,而且 jthread-1.2.1 必須先與 jrtp-3.7.1 的安裝。因為在 jrtp-3.7.1 的 configure 中,會尋找系統是否有編譯了 jthread 庫,如果有,那麼編譯的 jrtp 庫會開啟對 jthread 的支援。因此如果先編譯jrtp 在編譯 jthread ,編譯出來的 jrtp 是沒有開啟對 jthread 的支援的。如果採用第二種方法,那麼可以不用編譯 jthread 庫,而直接編譯 jrtp 庫。

 

jrtp-3.7.1.tar.gz 與 jthread-1.2.1.tar.gz 的

http://research.edm.uhasselt.be/~jori/page/index.php?n=CS.Jrtplib

 

 

一,編譯為 PC 所用:

PS:./configure –help 可以查看一些可以配置選項

jthread-1.2.1 的編譯

[[email protected] pc-jrtp]# tar -zxvf jthread-1.2.1.tar.gz

[[email protected] pc-jrtp]# cd jthread- 1.2.1

[[email protected] jthread-1.2.1]# ./configure  --prefix=/usr

[[email protected] jthread-1.2.1]# make

[[email protected] jthread-1.2.1]# make install

說明 : --prefix= 指定編譯後的 jthread 庫安裝到什麼目錄 。

 

安裝成功後在自己指定目錄下有 : include 與 lib 兩個檔案夾

include 中又有一個 jthread 的檔案夾,裡麵包含了 jthread 庫的標頭檔

lib 中包含了編譯成功的 jthread 庫:包括 動態庫 libjthread-1.2.1.so 與 靜態庫 libjthread.a

 

(2) jrtplib-3.7.1 的編譯

[[email protected] pc-jrtp]# tar -zxvf jrtplib-3.7.1.tar.gz

[[email protected] pc-jrtp]# cd jrtplib- 3.7.1

[[email protected] pc-jrtp]# ./configure --prefix=/usr/local/ --with-jthread-includes=/usr/local/include/jthread LDFLAGS=-L/usr/local/lib

說明:

--prefix= --prefix :指定編譯後的 jrtplib 庫安裝到什麼目錄。

--with-jthread-includes :指定之前安裝的 jthread 庫的標頭檔安裝在什麼目錄下。如果不需要 jthread 的支援,這個選項可以不用。

LDFLAGS :為編譯時間需要串連的動態庫的路徑。如果不需要 jthread 庫的支援,這個選項不要。

 

 

configure 過程中出現的提示資訊:

checking for JThread include files... in "/opt/mini2440/pc-jrtp/include/jthread"

checking JThread version... >= 1.1.0

checking if we can link against jthread and pthread... yes

說明 jthread 路徑正確,設定檔開啟了對 jthread 的支援。

 

接著進行 make 與 make install

[[email protected] jrtplib-3.7.1]# make

[[email protected] jrtplib-3.7.1]# make install

在不修改源檔案情況下 , make 的過程中直接編譯可能出現的錯誤:

在 Fedora 9 中 make 提示的錯誤:

rtppacket.cpp:311: error: ‘memcpy‘ was not declared in this scope

或者:

在 Fedora 13 中 make 提示的錯誤:

rtperrors.cpp: In function ‘std::string RTPGetErrorString(int)‘:

rtperrors.cpp:225: error: ‘snprintf‘ was not declared in this scope

為了 make 成功,需要修改 jrtplib-3.7.1 源檔案 rtpdefines.h

添加如下語句 : 
#include  
#include  
#include

操作如下:

[[email protected] jrtplib-3.7.1]# cd src/

[[email protected] src]# vim rtpdefines.h

// rtpdefines.h

75 #include

 

 

  78 #if (defined(WIN32) || defined(_WIN32_WCE))

  79         #if (!defined(_WIN32_WCE)) && (defined(_MSC_VER) && _MSC_VER >= 1400 )

  80                 #define RTP_SNPRINTF _snprintf_s

  81         #else

  82                 #define RTP_SNPRINTF _snprintf

  83         #endif

  84 #else

  85         #define RTP_SNPRINTF snprintf

  86 #endif // WIN32 || _WIN32_WCE

重新 make 後可以成功。

 

安裝成功後在自己指定目錄下有 :include 與 lib 兩個檔案夾

include 中又有一個 jrtplib 的檔案夾,裡麵包含了 jrtplib 庫的標頭檔

lib 中包含了編譯成功的 jrtp 庫:包括 動態庫 libjrtp-3.7.1.so 與 靜態庫 libjrtp.a 。

 

 

二,編譯為 MINI2440(ARM) 所用 :

步驟與編譯為 PC 所用一樣,但是 configure 的設定過有所不同,現在說明:

(1) 對於 jthread

./configure  --prefix=/opt/mini2440/arm-jrtp –host=arm-linux CC=arm-linux-gcc CXX=arm-linux-g++

(2) 對於 jrtlib

./configure –prefix=/opt/mini2440/arm-jrtp –host=arm-linux –with-jthread-includes=/opt/mini2440/arm-jrtp/includes CC=arm-linux-gcc CXX=arm-linux LDFLAGS=-L/opt/mini2440/arm-jrtp/lib

然後會看到如下提示資訊:

ASSUMING TARGET IS BIG ENDIAN:

    The script detected a cross-compiler on your system. This can mean that

  there really is a cross-compiler installed, or that for some other reason,

  a simple program could not be run. You should check the config.log file

  to verify this.

  Since we are assuming a cross-compiler, we won‘t be able to actually test

  any program. More important, we cannot test if the system is big or little

  endian.

  For now, big endian is assumed. If this assumption should be wrong, you will

  have to comment the appropriate line in ‘rtpconfig_unix.h‘

說明 : configure 把目標平台預設為是大端模式。如果需要改變則要修改 rtpconfig_ unix.h 。

 

我們那麼應該測試開發板是大端模式還是小端模式:

至於什麼是大端模式,什麼小端模式,以及為什麼要測試請看我部落格上的大端模式與小端模式。

 

測試程式:

1 #include

  2 int main(void)

  3 {

  4         int num = 0x1234;

  5         char *p = #

  6         if (*p == 0x12){

  7                 printf("Big Endian/n");

  8         }

  9         else{

  10                 printf("Little Endian/n");

  11         }

  12         return 0;

  13  }

儲存後用交叉編譯器編譯產生可執行檔後,放到目標平台上執行。從而判斷出目標平台是什麼模式。

通過測試下,得知 MINI2440 預設為小端模式,因此需要修改 rtpconfig_ unix.h

檔案在 :

/opt/mini2440/arm-jrtp/jrtplib-3.7.1/src

修改操作如下:

33 #ifndef RTPCONFIG_UNIX_H

  34

  35 #define RTPCONFIG_UNIX_H

  36

  37 // Don‘t have

  38

  39 // Don‘t have

  40

  41 //#define RTP_BIG_ENDIAN // comment this if the target is a little endian system

  42

  43 #define RTP_SOCKLENTYPE_UINT

則是把第 41 行注釋了 。注釋後則以小段模式來編譯。

然後就可以 make 與 make install 了。

 

三,最後一步就是測試了:

(1) 首先把編譯為 PC 所用的庫檔案: libjrtp-3.7.1.so 與 libjthread.so 複製到 Fedora9 的 /lib 。

(2) 把交叉編譯後產生的庫檔案 :libjrtp-3.7.1.so 與 libjthread.so 複製到開發板上的 /lib 。

(3) 執行 /opt/mini2440/pc-jrtp/jrtp-3.7.1/example 下的 exampl4 。

[[email protected] examples]# ./example4

Enter local portbase:

9090

 

 

Number of seconds you wish to wait:

500

 

(4) 把 /opt/mini2440/arm-jrtp/jrtp-3.7.1/example 目錄複寫到開發板上並執行 exampl1 。

[[email protected] download]# ./example1

Enter local portbase:

9090

 

Enter the destination IP address

192.168.0.2

Enter the destination port

9090

 

Number of packets you wish to be sent:

50

 

(5) 如果在 PC 上出現 Got packet 則表示可以收到開發板發過來的資料包

Got packet 32390 from SSRC 609572025

Got packet 32391 from SSRC 609572025

…….

 

遇到的問題:

編譯jrtplib的時候出現問題

rtperrors.cpp:206:1: warning: deprecated conversion from string constant to ‘cha
r*‘ [-Wwrite-strings]
rtperrors.cpp:206:1: warning: deprecated conversion from string constant to ‘cha
r*‘ [-Wwrite-strings]
rtperrors.cpp:206:1: warning: deprecated conversion from string constant to ‘cha
r*‘ [-Wwrite-strings]
rtperrors.cpp:206:1: warning: deprecated conversion from string constant to ‘cha
r*‘ [-Wwrite-strings]
rtperrors.cpp:206:1: warning: deprecated conversion from string constant to ‘cha
r*‘ [-Wwrite-strings]
rtperrors.cpp:206:1: warning: deprecated conversion from string constant to ‘cha
r*‘ [-Wwrite-strings]
rtperrors.cpp:206:1: warning: deprecated conversion from string constant to ‘cha
r*‘ [-Wwrite-strings]
rtperrors.cpp: In function ‘std::string RTPGetErrorString(int)‘:
rtperrors.cpp:225:36: error: ‘snprintf‘ was not declared in this scope
make[1]: *** [rtperrors.lo] 錯誤 1
make[1]:正在離開目錄 `/home/chenyu/chenyu/jrtplib-3.7.1/src‘

make: *** [all-recursive] 錯誤 1

 

解決方案:src目錄下找到rtpdefines.h檔案,在裡面加入:

#include <stdio.h> 
#include <stdarg.h> 
#include <string.h>

儲存,再次編譯,就可以了。。。。。。。。。。

 

參考:

1,ubuntu下jthread 和jrtplib的安裝

http://blog.sina.com.cn/s/blog_712a04260101c2bm.html

2,編譯jrtplib的時候出現問題

http://blog.csdn.net/chenyu123123/article/details/8743319

(轉)ubuntu下jthread 和jrtplib的安裝

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.