GB/T28181平台C++实现学习笔记1:编译jrtplib库写个HelloWorld引用库测试
听到一个面试官说这个库,搞个demo玩一玩。
下载
Cmake环境自己搞,我是搞过了。
JRTPLIB: https://github.com/j0r1/JRTPLIB
切最新tag:
git checkout v3.11.2
JThread: https://github.com/j0r1/JThread
切最新tag:
git checkout v1.3.3
不知道版本配套不,先不管,遇到问题再说。
编译JThread
本人洁癖,不喜欢什么都往系统里装,直接装到库目录./install里
#!/bin/bash
if [ -d "./install" ]; then
rm -rf install
fi
mkdir install
cd install
installPath=$(pwd)
cd ..
if [ -d "./build" ]; then
rm -rf build
fi
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=${installPath} ..
make
make install
cd ..
编译JRTPLIB
洁癖也是有代价的,JThread搜索不到,只好修改CMakeLists.txt文件,加上路径。
find_package(JThread PATHS /home/gj027/Test/C++/jrtplib/JThread/install)
#!/bin/bash
if [ -d "./install" ]; then
rm -rf install
fi
mkdir install
cd install
installPath=$(pwd)
cd ..
if [ -d "./build" ]; then
rm -rf build
fi
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=${installPath} ..
make
make install
cd ..
开搞
main.cpp
#include "rtpsession.h"
#include "rtpsessionparams.h"
#include "stdio.h"
using namespace jrtplib;
int main(void)
{
printf("Hello World\n");
RTPSession sess;
RTPSessionParams sessparams;
sessparams.SetOwnTimestampUnit(1.0/10.0);
sessparams.SetAcceptHello WorldOwnPackets(true);
int status = sess.Create(sessparams);
return 0;
}
CMakeLists.txt
# cmake最低版本
# Set the minimum required version of cmake for a project.
cmake_minimum_required(VERSION 3.0)
Hello WorldHello WorldHello World
# 项目名称
# Set a name, version, and enable languages for the entire project.
project(jrtplibTest VERSION 0.1.1)
message("=======================================")
message("项目版本信息")
message("---------------------------------------")
message(${PROJECT_NAME})
message(${PROJECT_SOURCE_DIR})
message(${PROJECT_BINARY_DIR})
message(${PROJECT_VERSION})
message("---------------------------------------")
# 源代码文件和头文件加入变量SRC_LIST(可多组)
# Find all source files in a directory.
aux_source_directory(. SRC_LIST)
message(STATUS "=======================================")
message(STATUS "项目源文件列表")
message(STATUS "---------------------------------------")
foreach(src_filename ${SRC_LIST})
message(STATUS ${src_filename})
endforeach(src_filename)
message(STATUS "---------------------------------------")
# 头文件路径(可多组)
# Add include directories to the build.
include_directories(../JRTPLIB/install/include)
include_directories(../JRTPLIB/install/include/jrtplib3)
include_directories(../JThread/install/include)
include_directories(../JThread/install/include/jthread)
# 库搜索路径(可多组)
# Specify directories in which the linker will look for libraries.
link_directories(../JRTPLIB/install/lib)
link_directories(../JThread/install/lib)
# 生成程序名
# Add an executable to the project using the specified source files.
ADD_EXECUTABLE(jrtplibTest ${SRC_LIST})
# 库名(可多组)
# Link a target to given libraries
target_link_libraries(jrtplibTest -ljrtp)
target_link_libraries(jrtplibTest -ljthread -lpthread)
set(CMAKE_INSTALL_BINDIR "bin")
message(STATUS "=======================================")
message(STATUS "CMAKE_INSTALL_BINDIR")
message(STATUS "---------------------------------------")
message(STATUS ${CMAKE_INSTALL_BINDIR})
message(STATUS "---------------------------------------")
install(
TARGETS jrtplibTest
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
# install(
# CODE "MESSAGE(\"Sample install message.\")"
# )## 找了一篇入门帖子,开搞
[https://www.cnblogs.com/yuweifeng/p/7550737.html](https://www.cnblogs.com/yuweifeng/p/7550737.html)
三年前的帖子,说有两个版本,必须搞新版本喽。
# INSTALL(TARGETS jrtplibTest
# RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
# )
build.sh
#!/bin/bash
if [ -d "./install" ]; then
rm -rf install
fi
mkdir install
cd install
installPath=$(pwd)
cd ..
Hello World
if [ -d "./build" ]; then
rm -rf build
fi
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=${installPath} ..
make
make install
cd ..
./run.sh
run.sh
#!/bin/bash
echo "#####jrtplibTest####### $*"
export LD_LIBRARY_PATH=/home/gj027/Test/C++/jrtplib/JRTPLIB/install/lib:/home/gj027/Test/C++/jrtplib/JThread/install/lib:$LD_LIBRARY_PATH
./install/bin/jrtplibTest
测试结果
Hello World
反正没有报错,明天继续。## 找了一篇入门帖子,开搞
参考帖子:
https://www.cnblogs.com/yuweifeng/p/7550737.html
微信号:yjkhtddx