打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Linux下编译jrtplib和jthread
操作环境:
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 = &num;
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行注释了。注释后则以小段模式来编译。
7.由于板子上的linux操作系统可以在没有用户名的情况下登录,所以rtpsession.cpp中的CreateCNAME可能报Can't retrieve login name的错误,因此需要修改几句代码:
[cpp] view plaincopy
if (!gotlogin)
{
char *logname = getenv("LOGNAME");
if (logname == 0)
{
strncpy((char*)buffer, "root", *bufferlength);
}
else
strncpy((char *)buffer,logname,*bufferlength);
}
.arm板运行时出现Can't retrieve login name
原因:RTP的JRTPLIB库中的RTPSession中的Create->InternalCreate->CreateCNAME中,有对用户名进行一定操作,其中的getlogin_r(),getlogin()和getenv()操作都会因为用户名为空,而返回错误ERR_RTP_SESSION_CANTGETLOGINNAME。
解决的方式有3种:1)在开发板上输入export   LOGNAME=root  2)大部分开发板还是需要用户名登陆的,即在文件系统完全启动后再运行,也能解决。 3)因为板子上的文件系统有时不需要用户名就可以直接登录,而在我们可以通过修改JRTPLIB库的CreateCNAME源代码来为系统默认设置一个用户名。在RTPSession.cpp的第1400行。
然后就可以make与make install了。
三,最后一步就是测试了:
(1) 首先把编译为PC所用的库文件:libjrtp-3.7.1.so与libjthread.so复制到Fedora9的 /lib。
(2) 把交叉编译后生成的库文件:libjrtp-3.7.1.so与libjthread.so复制到开发板上的/lib。
把.so  .a 复制到交叉编译器的/target/usr/lib目录下
.h复制到交叉编译器的/target/usr/include目录下或者用软连接链接到此目录下#ln -s  /...  /....
接下来还要修改源码中的 include 的
修改makefile
LD=arm-hisiv200-linux-g++
#LD=ppc_6xx-gcc
TARGET = rtp
OBJS = $(TARGET).o
#LIBS = -/usr/local/lib/libjthread.so -/usr/local/lib/libjrtp.so
LIBS = -ljthread -ljrtp
SRC = main.cpp jrtpplayer.cpp
%.o:%.c \
$(LD) -c $< -o $@
$(TARGET).o: $(SRC:.c=.o)
$(LD) $(SRC) -static -o $(TARGET) $(LIBS)
clean:
rm -f *.o $(EXEC) $(TARGET)
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
x86 linux以及arm linux编译JRTPLIB
Qt 5.9.4 如何静态编译和部署?
pkg
使用scons替代makefile(2)
Ubuntu安装Oracle 12c过程及相关问题解决
arm-Linux下用到数据库sqlite3
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服