作業環境:
Host OS: Windows 7
VMware Workstation:6.5.1
Guest OS: Fedora 9
Develop Board: MINI2440
Cross-Complier: ARM-Linux-GCC 4.3.2
關於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的編譯
[root@localhost pc-jrtp]# tar -zxvf jthread-1.2.1.tar.gz
[root@localhost pc-jrtp]# cd jthread-1.2.1
[root@localhost jthread-1.2.1]# ./configure --prefix=/opt/mini2440/pc-jrtp
[root@localhost jthread-1.2.1]# make
[root@localhost jthread-1.2.1]# make install
說明: --prefix=指定編譯後的jthread庫安裝到什麼目錄。
執行make install時會出現如下資訊:
-----------------------------------------------------------------
Libraries have been installed in:
/opt/mini2440/pc-jrtp/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
-----------------------------------------------------------------
這段英文告訴我們編譯後的jthread庫安裝到什麼目錄下,而且如果使用這個庫編譯自己的檔案應該怎麼做。可以參考靜態函數庫與動態函數庫。
安裝成功後在自己指定目錄下有:include與lib兩個檔案夾
include中又有一個jthread的檔案夾,裡麵包含了jthread庫的標頭檔
lib中包含了編譯成功的jthread庫:包括動態庫libjthread-1.2.1.so與靜態庫libjthread.a
(2) jrtplib-3.7.1的編譯
[root@localhost pc-jrtp]# tar -zxvf jrtplib-3.7.1.tar.gz
[root@localhost pc-jrtp]# cd jrtplib-3.7.1
[root@localhost pc-jrtp]#./configure--prefix=/opt/mini2440/pc-jrtp/--with-jthread-includes=/opt/mini2440/pc-jrtp/include/jthreadLDFLAGS=-L/opt/mini2440/pc-jrtp/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
[root@localhost jrtplib-3.7.1]# make
[root@localhost 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 <stdio.h>
#include <stdarg.h>
#include <string.h>
操作如下:
[root@localhost jrtplib-3.7.1]# cd src/
[root@localhost src]# vim rtpdefines.h
// rtpdefines.h
75 #include <stdio.h>
76 #include <stdarg.h>
77 #include <string.h>
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後可以成功。
make isntall後有如下資訊
-----------------------------------------------------------------
Libraries have been installed in:
/opt/mini2440/pc-jrtp/lib
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `LD_LIBRARY_PATH' environment variable
during execution
- add LIBDIR to the `LD_RUN_PATH' environment variable
during linking
- use the `-Wl,--rpath -Wl,LIBDIR' linker flag
- have your system administrator add LIBDIR to `/etc/ld.so.conf'
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
-----------------------------------------------------------------
這段英文告訴我們編譯後的jrtp庫安裝到什麼目錄下,而且如果使用這個庫編譯自己的檔案應該怎麼做。
安裝成功後在自己指定目錄下有: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-gccCXX=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。
[root@localhost 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。
[root@FriendlyARM 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
…….
轉自:http://blog.csdn.net/elevenxjz/article/details/6043369