折腾two days终于编译OK,主要参考http://blog.csdn.net/nickwar/article/details/9133399 https://github.com/jimjh/JRTPLib-for-Android,资源且少,越发珍贵,做一记录。
1.平台
win7 ndk-r8d cmake2.8 msys1.0
cmake用法百度
2.下载源码解压
!!!.注意目录和子目录均有CmakeLIst,两文件内容不同,位置不要乱动。
先说Jthread编译,src目录下有源码和头文件(编译时遇到最多的错误就是找不见头文件,或者头文件顺序不当引起的诡异error)
在jthread目录下:
1 打开CmakeList文件
注释这些,其实不注释也可以,暂且这么做
# find_package(Threads) # if (NOT CMAKE_USE_WIN32_THREADS_INIT) # if (NOT CMAKE_USE_PTHREADS_INIT) # message(FATAL_ERROR "Can find neither pthread support nor Win32 thread support") # endif (NOT CMAKE_USE_PTHREADS_INIT) # endif (NOT CMAKE_USE_WIN32_THREADS_INIT)2 在jthread下新建一个android-build目录以放置生成好的库及头文件
3 src/pthread/jthread.cpp的125行,找到pthread_cancel(threadid);并注释之,替换成 pthread_kill(threadid, SIGUSR1); 原因么,是因为android用的自家产的Bionic libc而不是标准glibc,具体可wikipedia之。
4,最重要的android.sh,就在jthread的下创建
<span style="color:#222222;">#!/bin/sh # Written by Nxf <[email protected]> # # Builds the JThread library for Android export NDK_ROOT="D:/android-ndk-r8d-windows/android-ndk-r8d" </span><span style="color:#ff0000;">改成自己路径</span><span style="color:#222222;"> export PATH="${NDK_ROOT}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/:${PATH}" SYS_ROOT="${NDK_ROOT}/platforms/android-14/arch-arm" PREF="arm-linux-androideabi-" OUT_DIR="D:/sh/jthread/android-build" C_FLAGS="-lstdc++ -lsupc++ \ -I${NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/4.4.3/include \ -I${NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/4.4.3/libs/armeabi/include \ -L${NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/4.4.3/libs/armeabi" #set -e export CC="${NDK_ROOT}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/${PREF}gcc --sysroot=${SYS_ROOT}" export CXX="${NDK_ROOT}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/${PREF}g++ --sysroot=${SYS_ROOT}" export LD="$${NDK_ROOT}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/{PREF}ld --sysroot=${SYS_ROOT}" export CPP="${NDK_ROOT}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/${PREF}cpp --sysroot=${SYS_ROOT}" export AS="${NDK_ROOT}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/${PREF}as" export OBJCOPY="${NDK_ROOT}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/${PREF}objcopy" export OBJDUMP="${NDK_ROOT}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/${PREF}objdump" export STRIP="${NDK_ROOT}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/${PREF}strip" export RANLIB="${NDK_ROOT}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/${PREF}ranlib" export CCLD="${NDK_ROOT}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/${PREF}gcc --sysroot=${SYS_ROOT}" export AR="${NDK_ROOT}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/${PREF}ar" cmake \ -DCMAKE_SYSTEM_NAME="Generic" \ -DCMAKE_CXX_FLAGS="${C_FLAGS}"\ -DCMAKE_FIND_ROOT_PATH="${SYS_ROOT}" \ -DCMAKE_INSTALL_PREFIX="${OUT_DIR}" \ -G "MSYS Makefiles" . /D/android-ndk-r8d-windows/android-ndk-r8d/prebuilt/windows/bin/make.exe </span><span style="color: rgb(34, 34, 34); font-family: SimSun;"> </span><span style="font-family: SimSun; color: rgb(255, 0, 0);">改成自己路径</span><span style="color:#222222;"> /D/android-ndk-r8d-windows/android-ndk-r8d/prebuilt/windows/bin/make.exe install cd ${OUT_DIR}/lib && \ ${AR} -x libjthread.a && \ ${CXX} ${C_FLAGS} -shared -Wl,-soname,libjthread.so -o libjthread.so *.obj && \ rm *.obj exit 0</span>5.在msys中,cd的当前路径,运行./android.sh
libjthread.a 和.so文件生成,还算比较顺利。
下面开始jrtplib
步骤基本同前,知识改文件稍多
1.修改Cmakelist,传输中的大小端问题,也可以不该,为什么?细心的读者会发现有个 rtpconfig.h.in,此非头文件,内容却像,稍后再说。
if (CMAKE_CROSSCOMPILING) # option (JRTPLIB_USE_BIGENDIAN "Target platform is big endian" ON) # if (JRTPLIB_USE_BIGENDIAN) # set(RTP_ENDIAN "#define RTP_BIG_ENDIAN") # else (JRTPLIB_USE_BIGENDIAN) set(RTP_ENDIAN "// Little endian system") # endif (JRTPLIB_USE_BIGENDIAN) else (CMAKE_CROSSCOMPILING) # test_big_endian(JRTPLIB_BIGENDIAN) # if (JRTPLIB_BIGENDIAN) # set(RTP_ENDIAN "#define RTP_BIG_ENDIAN") # else (JRTPLIB_BIGENDIAN) set(RTP_ENDIAN "// Little endian system") # endif (JRTPLIB_BIGENDIAN) endif (CMAKE_CROSSCOMPILING)2.android.sh
#!/bin/sh # # Builds the JThread library for Android export NDK_ROOT="D:/android-ndk-r8d-windows/android-ndk-r8d" export PATH="${NDK_ROOT}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/:${PATH}" SYS_ROOT="${NDK_ROOT}/platforms/android-14/arch-arm" PREF="arm-linux-androideabi-" J="D:/rtp/jthread/src" OUT_DIR="D:/rtp/jrtplib/android-build" #C_FLAGS="-lstdc++ -lsupc++ \ # -I${NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/4.4.3/include \ # -I${NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/4.4.3/libs/armeabi/include \ # -L${NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/4.4.3/libs/armeabi" # -L${J} " C_FLAGS="-lstdc++ -lsupc++ \ <span style="color:#ff0000;">原作上面两个参数去掉,编译不碍</span> -I${NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/4.4.3/include \ -I${NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/4.4.3/libs/armeabi/include \ -L${NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/4.4.3/libs/armeabi \ -L${J}" #set -e export CC="${NDK_ROOT}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/${PREF}gcc --sysroot=${SYS_ROOT}" export CXX="${NDK_ROOT}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/${PREF}g++ --sysroot=${SYS_ROOT}" export LD="$${NDK_ROOT}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/{PREF}ld --sysroot=${SYS_ROOT}" export CPP="${NDK_ROOT}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/${PREF}cpp --sysroot=${SYS_ROOT}" export AS="${NDK_ROOT}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/${PREF}as" export OBJCOPY="${NDK_ROOT}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/${PREF}objcopy" export OBJDUMP="${NDK_ROOT}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/${PREF}objdump" export STRIP="${NDK_ROOT}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/${PREF}strip" export RANLIB="${NDK_ROOT}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/${PREF}ranlib" export CCLD="${NDK_ROOT}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/${PREF}gcc --sysroot=${SYS_ROOT}" export AR="${NDK_ROOT}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/${PREF}ar" cmake \ -DCMAKE_SYSTEM_NAME="Generic" \ -DCMAKE_CXX_FLAGS="${C_FLAGS}"\ -DCMAKE_FIND_ROOT_PATH="${SYS_ROOT}" \ -DJTHREAD_INCLUDE_DIRS="${J}" \<span style="color:#ff0000;"> 改这行及下面</span> -DJTHREAD_LIBRARIES="${J}" \ -DCMAKE_PREFIX_PATH="D:/rtp/jthread/android-build" \ -DCMAKE_INSTALL_PREFIX="${OUT_DIR}" \ -G "MSYS Makefiles" . /D/android-ndk-r8d-windows/android-ndk-r8d/prebuilt/windows/bin/make.exe /D/android-ndk-r8d-windows/android-ndk-r8d/prebuilt/windows/bin/make.exe install cd ${OUT_DIR}/lib && \ # ${AR} -x libjthread.a && \ # ${CXX} ${C_FLAGS} -shared -Wl,-soname,libjthread.so -o libjthread.so *.obj && \ ${AR} -x libjrtplib.a && \ ${CXX} ${C_FLAGS} -shared -Wl,-soname,libjrtplib.so -o libjrtplib.so *.obj && \ rm *.obj exit 0
3.头文件有误了自己改改路径都能解决,add_subdirectory(examples) 错误,注释即可
android项目即可使用,之前没用过msys,所以还想尝试了下windown 下android ndk 编译,下篇讲。