linux下编译jrtplib-3.9.1

来源:互联网 发布:淘宝刷一个钻多少钱 编辑:程序博客网 时间:2024/06/10 23:18

网站:http://blog.csdn.net/caoshangpa/article/details/51416822


一、下载jrtplib、jthread、CMake

jrtplib:http://research.edm.uhasselt.be/jori/jrtplib/jrtplib-3.9.1.zip

jthread:http://research.edm.uhasselt.be/jori/jthread/jthread-1.3.1.zip

CMake:https://cmake.org/download/,最新版已经到3.5.1,我用的是3.4.0

注意,如果jrtplib编译过程中报错/usr/bin/ld:cannot find -lIN,参考:http://blog.csdn.NET/caoshangpa/article/details/51416500

二、编译

1.jthread编译

修改CMakeLists.txt,如下所示,注意添加的部分。

[cpp] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. cmake_minimum_required(VERSION 2.6)  
  2.   
  3. project(jthread)  
  4. set(VERSION 1.3.1)  
  5. #************************************添加开始******************************  
  6. #告知当前使用的是交叉编译方式    
  7. SET(CMAKE_SYSTEM_NAME Linux)    
  8. #设置c编译器    
  9. SET(CMAKE_C_COMPILER "gcc")    
  10. #设置c++编译器    
  11. SET(CMAKE_CXX_COMPILER "g++")  
  12. #设置安装路径  
  13. set(CMAKE_INSTALL_PREFIX "/usr/local/jrtplibRedHat")  
  14. #************************************添加结束******************************  
  15. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")  
  16. set (_DEFAULT_LIBRARY_INSTALL_DIR lib)  
  17. if (EXISTS "${CMAKE_INSTALL_PREFIX}/lib32/" AND CMAKE_SIZEOF_VOID_P EQUAL 4)  
  18.     set (_DEFAULT_LIBRARY_INSTALL_DIR lib32)  
  19. elseif (EXISTS "${CMAKE_INSTALL_PREFIX}/lib64/" AND CMAKE_SIZEOF_VOID_P EQUAL 8)  
  20.     set (_DEFAULT_LIBRARY_INSTALL_DIR lib64)  
  21. endif ()  
  22.   
  23. set(LIBRARY_INSTALL_DIR "${_DEFAULT_LIBRARY_INSTALL_DIR}" CACHE PATH "Library installation directory")  
  24. if(NOT IS_ABSOLUTE "${LIBRARY_INSTALL_DIR}")  
  25.     set(LIBRARY_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${LIBRARY_INSTALL_DIR}")  
  26. endif()  
  27.   
  28. find_package(Threads)  
  29. if (NOT CMAKE_USE_WIN32_THREADS_INIT)  
  30.     if (NOT CMAKE_USE_PTHREADS_INIT)  
  31.         message(FATAL_ERROR "Can find neither pthread support nor Win32 thread support")  
  32.     endif (NOT CMAKE_USE_PTHREADS_INIT)  
  33. endif (NOT CMAKE_USE_WIN32_THREADS_INIT)  
  34.   
  35. add_subdirectory(src)  

cmake CMakeLists.txt

make

make install

2.jrtplib编译

修改CMakeLists.txt,如下所示,注意添加和修改的部分。

[cpp] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. cmake_minimum_required(VERSION 2.6)  
  2.   
  3. project(jrtplib)  
  4. set(VERSION 3.9.1)  
  5. #************************************添加开始******************************  
  6. #告知当前使用的是交叉编译方式    
  7. SET(CMAKE_SYSTEM_NAME Linux)    
  8. #设置c编译器    
  9. SET(CMAKE_C_COMPILER "gcc")    
  10. #设置c++编译器    
  11. SET(CMAKE_CXX_COMPILER "g++")  
  12. #设置安装路径  
  13. set(CMAKE_INSTALL_PREFIX "/usr/local/jrtplibRedHat")  
  14. #************************************添加结束******************************  
  15. set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")  
  16.   
  17. set (_DEFAULT_LIBRARY_INSTALL_DIR lib)  
  18. if (EXISTS "${CMAKE_INSTALL_PREFIX}/lib32/" AND CMAKE_SIZEOF_VOID_P EQUAL 4)  
  19.     set (_DEFAULT_LIBRARY_INSTALL_DIR lib32)  
  20. elseif (EXISTS "${CMAKE_INSTALL_PREFIX}/lib64/" AND CMAKE_SIZEOF_VOID_P EQUAL 8)  
  21.     set (_DEFAULT_LIBRARY_INSTALL_DIR lib64)  
  22. endif ()  
  23.   
  24. set(LIBRARY_INSTALL_DIR "${_DEFAULT_LIBRARY_INSTALL_DIR}" CACHE PATH "Library installation directory")  
  25. if(NOT IS_ABSOLUTE "${LIBRARY_INSTALL_DIR}")  
  26.     set(LIBRARY_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${LIBRARY_INSTALL_DIR}")  
  27. endif()  
  28.   
  29. include(CheckCXXCompilerFlag)  
  30. include(CheckIncludeFile)  
  31. include(CheckIncludeFileCXX)  
  32. include(CheckCXXSourceCompiles)  
  33. include(TestBigEndian)  
  34. include(${PROJECT_SOURCE_DIR}/cmake/Macros.cmake)  
  35.   
  36. find_package(JThread)  
  37.   
  38. set(JRTPLIB_LINK_LIBS "")  
  39. #************************************修改开始******************************  
  40. set(JRTPLIB_INTERNAL_INCLUDES "/usr/local/jrtplibRedHat/include")  
  41. set(JRTPLIB_EXTERNAL_INCLUDES "/usr/local/jrtplibRedHat/include")  
  42. #************************************修改结束******************************  
  43. add_additional_stuff(JRTPLIB_EXTERNAL_INCLUDES JRTPLIB_LINK_LIBS)  
  44.   
  45. jrtplib_support_option("Support SDES PRIV items" JRTPLIB_SUPPORT_SDESPRIV RTP_SUPPORT_SDESPRIV ON "// No support for SDES PRIV items")  
  46. jrtplib_support_option("Support the probation mechanism for a new source" JRTPLIB_SUPPORT_PROBATION RTP_SUPPORT_PROBATION ON "// Do not wait for a number of consecutive packets to validate source")  
  47. jrtplib_support_option("Support sending RTCP APP packets" JRTPLIB_SUPPORT_SENDAPP RTP_SUPPORT_SENDAPP ON "// No direct support for sending RTCP APP packets")  
  48. jrtplib_support_option("Support sending unknown RTCP packets" JRTPLIB_SUPPORT_RTCPUNKNOWN RTP_SUPPORT_RTCPUNKNOWN OFF "// No support for sending unknown RTCP packets")  
  49. jrtplib_support_option("Support memory management mechanism" JRTPLIB_SUPPORT_MEMORYMGMT RTP_SUPPORT_MEMORYMANAGEMENT ON "// No memory management support")  
  50.   
  51. jrtplib_include_test(sys/filio.h RTP_HAVE_SYS_FILIO "// Don't have <sys/filio.h>")  
  52. jrtplib_include_test(sys/sockio.h RTP_HAVE_SYS_SOCKIO "// Don't have <sys/sockio.h>")  
  53. jrtplib_include_test(ifaddrs.h RTP_SUPPORT_IFADDRS "// No ifaddrs support")  
  54.   
  55. if (JTHREAD_FOUND)  
  56.     set(V "ON")  
  57. else (JTHREAD_FOUND)  
  58.     set(V "OFF")  
  59. endif (JTHREAD_FOUND)  
  60.   
  61. option(JTHREAD_ENABLED "Thread support" ${V})  
  62. if (JTHREAD_ENABLED)  
  63.     set (RTP_SUPPORT_THREAD "#define RTP_SUPPORT_THREAD")  
  64.     if (JTHREAD_FOUND)  
  65.         save_paths(JRTPLIB_EXTERNAL_INCLUDES "${JTHREAD_INCLUDE_DIRS}")  
  66.         save_paths(JRTPLIB_LINK_LIBS "${JTHREAD_LIBRARIES}")  
  67.     endif(JTHREAD_FOUND)  
  68. else (JTHREAD_ENABLED)  
  69.     set (RTP_SUPPORT_THREAD "// No support for JThread was enabled")  
  70. endif (JTHREAD_ENABLED)  
  71.   
  72. if (CMAKE_CROSSCOMPILING)  
  73.     option (JRTPLIB_USE_BIGENDIAN "Target platform is big endian" ON)  
  74.     if (JRTPLIB_USE_BIGENDIAN)  
  75.         set(RTP_ENDIAN "#define RTP_BIG_ENDIAN")  
  76.     else (JRTPLIB_USE_BIGENDIAN)  
  77.         set(RTP_ENDIAN "// Little endian system")  
  78.     endif (JRTPLIB_USE_BIGENDIAN)  
  79. else (CMAKE_CROSSCOMPILING)  
  80.     test_big_endian(JRTPLIB_BIGENDIAN)  
  81.     if (JRTPLIB_BIGENDIAN)  
  82.         set(RTP_ENDIAN "#define RTP_BIG_ENDIAN")  
  83.     else (JRTPLIB_BIGENDIAN)  
  84.         set(RTP_ENDIAN "// Little endian system")  
  85.     endif (JRTPLIB_BIGENDIAN)  
  86. endif (CMAKE_CROSSCOMPILING)  
  87.   
  88. jrtplib_test_feature(socklentest RTP_SOCKLENTYPE_UINT TRUE "// socklen_t is 'int'")  
  89. jrtplib_test_feature(ipv4mcasttest RTP_SUPPORT_IPV4MULTICAST FALSE "// No IPv4 multicasting support")  
  90. jrtplib_test_feature(salentest RTP_HAVE_SOCKADDR_LEN FALSE "// No sa_len member in struct sockaddr")  
  91. jrtplib_test_feature(getloginrtest RTP_SUPPORT_GETLOGINR FALSE "// Not using getlogin_r")  
  92. jrtplib_test_feature(ipv6test RTP_SUPPORT_IPV6 FALSE "// No IPv6 support")  
  93. jrtplib_test_feature(ipv6mcasttest RTP_SUPPORT_IPV6MULTICAST FALSE "// No IPv6 multicasting support")  
  94.   
  95. check_cxx_source_compiles("#include <stdint.h>\n#include <sys/types.h>\nint main(void) { size_t a = 0 ; size_t b = a; uint32_t x = 0; uint32_t y = x; return 0; }" JRTPLIB_STDINT)  
  96. if (JRTPLIB_STDINT)  
  97.     set(RTP_INTTYPE_HEADERS "#include <stdint.h>\n#include <sys/types.h>")  
  98. else (JRTPLIB_STDINT)  
  99.     check_cxx_source_compiles("#include <inttypes.h>\n#include <sys/types.h>\nint main(void) { uint32_t x = 0; uint32_t y = x; return 0; }" JRTPLIB_INTTYPES)  
  100.     if (JRTPLIB_INTTYPES)  
  101.         set(RTP_INTTYPE_HEADERS "#include <inttypes.h>\n#include <sys/types.h>\n")  
  102.     else (JRTPLIB_INTTYPES)  
  103.         if (NOT UNIX AND WIN32)  
  104.             set(RTP_INTTYPE_HEADERS "#include \"rtptypes_win.h\"")  
  105.         else (NOT UNIX AND WIN32)  
  106.             set(RTP_INTTYPE_HEADERS "#error Could not find header files that define types like 'uint32_t'. Please edit the file ${PROJECT_BINARY_DIR}/src/rtptypes_unix.h and make sure that the following types are defined: int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t")  
  107.             message("\n\nError: Could not find header files that define types like 'uint32_t'.\nPlease edit the file ${PROJECT_BINARY_DIR}/src/rtptypes_unix.h\nand make sure that the following types are defined: \nint8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t\n\n")  
  108.         endif (NOT UNIX AND WIN32)  
  109.     endif (JRTPLIB_INTTYPES)  
  110. endif (JRTPLIB_STDINT)  
  111.   
  112. if (NOT UNIX AND WIN32)  
  113.     set(RTP_WINSOCK_HEADERS "#if defined(WIN32) || defined(_WIN32_WCE)\n    #include <winsock2.h> \n  #include <ws2tcpip.h>\n#ifndef _WIN32_WCE\n   #include <sys/types.h>\n#endif // _WIN32_WCE\n#endif // WIN32 || _WIN32_WCE\n")  
  114. endif (NOT UNIX AND WIN32)  
  115.   
  116. if (NOT UNIX)  
  117.     set(JRTPLIB_COMPILE_STATIC ON CACHE BOOL "Flag indicating if a static library should be built, or a dynamic one")  
  118.     list(APPEND JRTPLIB_LINK_LIBS "ws2_32")  
  119. endif (NOT UNIX)  
  120.   
  121. if (UNIX OR JRTPLIB_COMPILE_STATIC)  
  122.     set(JRTPLIB_IMPORT "")  
  123.     set(JRTPLIB_EXPORT "")  
  124. else (UNIX OR JRTPLIB_COMPILE_STATIC)  
  125.     set(JRTPLIB_IMPORT "__declspec(dllimport)")  
  126.     set(JRTPLIB_EXPORT "__declspec(dllexport)")  
  127. endif (UNIX OR JRTPLIB_COMPILE_STATIC)  
  128.   
  129. configure_file("${PROJECT_SOURCE_DIR}/src/rtptypes.h.in" "${PROJECT_BINARY_DIR}/src/rtptypes.h")  
  130. configure_file("${PROJECT_SOURCE_DIR}/src/rtpconfig.h.in" "${PROJECT_BINARY_DIR}/src/rtpconfig.h")  
  131.   
  132. save_paths(JRTPLIB_INTERNAL_INCLUDES "${PROJECT_SOURCE_DIR}/src" "${PROJECT_BINARY_DIR}/src")  
  133.   
  134. add_subdirectory(src)  
  135.   
  136.    
  137. if (UNIX)  
  138.     get_target_property(JRTPLIB_LOCAL_LIBRARY_NAME jrtplib-shared LOCATION)  
  139.     get_filename_component(JRTPLIB_LIBNAME "${JRTPLIB_LOCAL_LIBRARY_NAME}" NAME)  
  140.     set(JRTPLIB_LIBS "${LIBRARY_INSTALL_DIR}/${JRTPLIB_LIBNAME}")  
  141. else (UNIX)  
  142.     if (JRTPLIB_COMPILE_STATIC)  
  143.         get_target_property(JRTPLIB_LOCAL_LIBRARY_NAME jrtplib-static RELEASE_LOCATION)  
  144.         get_filename_component(JRTPLIB_LIBNAME_RELEASE "${JRTPLIB_LOCAL_LIBRARY_NAME}" NAME_WE)  
  145.         get_target_property(JRTPLIB_LOCAL_LIBRARY_NAME jrtplib-static DEBUG_LOCATION)  
  146.         get_filename_component(JRTPLIB_LIBNAME_DEBUG "${JRTPLIB_LOCAL_LIBRARY_NAME}" NAME_WE)  
  147.     else (JRTPLIB_COMPILE_STATIC)  
  148.         get_target_property(JRTPLIB_LOCAL_LIBRARY_NAME jrtplib-shared RELEASE_LOCATION)  
  149.         get_filename_component(JRTPLIB_LIBNAME_RELEASE "${JRTPLIB_LOCAL_LIBRARY_NAME}" NAME_WE)  
  150.         get_target_property(JRTPLIB_LOCAL_LIBRARY_NAME jrtplib-shared DEBUG_LOCATION)  
  151.         get_filename_component(JRTPLIB_LIBNAME_DEBUG "${JRTPLIB_LOCAL_LIBRARY_NAME}" NAME_WE)  
  152.     endif (JRTPLIB_COMPILE_STATIC)  
  153.     set(JRTPLIB_LIBS optimized "${LIBRARY_INSTALL_DIR}/${JRTPLIB_LIBNAME_RELEASE}.lib"   
  154.                  debug "${LIBRARY_INSTALL_DIR}/${JRTPLIB_LIBNAME_DEBUG}.lib")  
  155. endif (UNIX)  
  156.   
  157. set(JRTPLIB_INCDIRS ${JRTPLIB_EXTERNAL_INCLUDES} ${CMAKE_INSTALL_PREFIX}/include)  
  158. set(JRTPLIB_LIBS ${JRTPLIB_LIBS} ${JRTPLIB_LINK_LIBS})  
  159. remove_empty(JRTPLIB_INCDIRS)  
  160. list(REMOVE_DUPLICATES JRTPLIB_INCDIRS)  
  161. remove_empty(JRTPLIB_LIBS)  
  162.   
  163. foreach(ARG ${JRTPLIB_LIBS})  
  164.     set(JRTPLIB_LIBS_CMAKECONFIG "${JRTPLIB_LIBS_CMAKECONFIG} \"${ARG}\"")  
  165. endforeach()  
  166. foreach(ARG ${JRTPLIB_INCDIRS})  
  167.     set(JRTPLIB_INCDIRS_CMAKECONFIG "${JRTPLIB_INCDIRS_CMAKECONFIG} \"${ARG}\"")  
  168. endforeach()  
  169.   
  170. configure_file("${PROJECT_SOURCE_DIR}/cmake/JRTPLIBConfig.cmake.in" "${PROJECT_BINARY_DIR}/cmake/JRTPLIBConfig.cmake")  
  171. install(FILES "${PROJECT_BINARY_DIR}/cmake/JRTPLIBConfig.cmake" DESTINATION ${LIBRARY_INSTALL_DIR}/cmake/JRTPLIB)  
  172.   
  173. if (UNIX)  
  174.     foreach(ARG ${JRTPLIB_LIBS})  
  175.         set(JRTPLIB_LIBS_PKGCONFIG "${JRTPLIB_LIBS_PKGCONFIG} ${ARG}")  
  176.     endforeach()  
  177.     foreach(ARG ${JRTPLIB_INCDIRS})  
  178.         set(JRTPLIB_INCDIRS_PKGCONFIG "${JRTPLIB_INCDIRS_PKGCONFIG} -I${ARG}")  
  179.     endforeach()  
  180.   
  181.     configure_file(${PROJECT_SOURCE_DIR}/pkgconfig/jrtplib.pc.in ${PROJECT_BINARY_DIR}/pkgconfig/jrtplib.pc)  
  182.     install(FILES ${PROJECT_BINARY_DIR}/pkgconfig/jrtplib.pc DESTINATION ${LIBRARY_INSTALL_DIR}/pkgconfig)  
  183. endif (UNIX)  

cmake CMakeLists.txt

make

make install



0 0
原创粉丝点击