编译环境:Ubuntu15.04_64
使用ninja进行编译
WebRTC默认编译的是针对ARM架构的,在MIPS架构的CPU上运行会报错。
步骤如下:(前提是你已经下好了源码,我的源码是2015年7月份下载的)
1、export GYP_DEFINES="OS=android target_arch=mipsel"//指定编译为MIPS架构
2、python webrtc/build/gyp_webrtc //生成对应的ninja文件
3、ninja -C out/Debug //开始编译
编译的过程中,我的会报错:
shine@guopeng:~/WorkSpace/webrtc/src$ ninja -C out/Debug
ninja: Entering directory `out/Debug'
[2878/3843] LINK audio_device_tests
FAILED: /home/shine/WorkSpace/webrtc/src/third_party/android_tools/ndk//toolchai
ns/mipsel-linux-android-4.9/prebuilt/linux-x86_64/bin/mipsel-linux-android-g++ -
Wl,-z,now -Wl,-z,relro -Wl,--fatal-warnings -Wl,-z,defs -Wl,-z,noexecstack -fPIC
-Wl,--no-keep-memory -Wl,--build-id=sha1 -Wl,--no-undefined --sysroot=../../thi
rd_party/android_tools/ndk//platforms/android-16/arch-mips -nostdlib -L../../thi
rd_party/android_tools/ndk//sources/cxx-stl/llvm-libc++/libs/mips -Wl,--exclude-
libs=libgcc.a -Wl,--exclude-libs=libc++_static.a -Wl,--exclude-libs=libcommon_au
dio.a -Wl,--exclude-libs=libcommon_audio_neon.a -Wl,--exclude-libs=libcommon_aud
io_sse2.a -Wl,--exclude-libs=libiSACFix.a -Wl,--exclude-libs=libisac_neon.a -Wl,
--exclude-libs=libopus.a -Wl,--exclude-libs=libvpx.a -Bdynamic -Wl,--gc-sections
-Wl,-z,nocopyreloc -pie -rdynamic ../../third_party/android_tools/ndk//platform
s/android-16/arch-mips/usr/lib/crtbegin_dynamic.o -Wl,--version-script=/home/shi
ne/WorkSpace/webrtc/src/build/android/android_no_jni_exports.lst -Wl,-O1 -Wl,--a
s-needed -o audio_device_tests -Wl,--start-group obj/webrtc/modules/audio_device
/test/audio_device_tests.audio_device_test_api.o obj/webrtc/modules/libaudio_dev
ice.a obj/webrtc/modules/libwebrtc_utility.a obj/webrtc/test/libtest_support_mai
n.a obj/chromium/src/testing/libgtest.a obj/webrtc/system_wrappers/libsystem_wra
ppers.a obj/webrtc/modules/libaudio_coding_module.a obj/webrtc/modules/libcng.a
obj/webrtc/common_audio/libcommon_audio.a obj/webrtc/libwebrtc_common.a obj/webr
tc/base/librtc_base_approved.a obj/webrtc/system_wrappers/libcpu_features_androi
d.a obj/chromium/src/build/android/libcpu_features.a obj/chromium/src/third_part
y/openmax_dl/dl/libopenmax_dl.a obj/webrtc/modules/libaudio_encoder_interface.a
obj/webrtc/modules/libg711.a obj/webrtc/modules/libg722.a obj/webrtc/modules/lib
ilbc.a obj/webrtc/modules/libisac.a obj/webrtc/modules/libaudio_decoder_interfac
e.a obj/webrtc/modules/libisac_fix.a obj/webrtc/modules/libpcm16b.a obj/webrtc/m
odules/libred.a obj/webrtc/modules/libwebrtc_opus.a obj/chromium/src/third_party
/opus/libopus.a obj/webrtc/modules/libneteq.a obj/webrtc/modules/libmedia_file.a
obj/webrtc/test/libfield_trial.a obj/webrtc/test/libhistogram.a obj/webrtc/test
/libtest_support.a obj/chromium/src/testing/libgmock.a obj/third_party/gflags/li
bgflags.a -Wl,--end-group -llog -lOpenSLES -lm -lc++_static -latomic /home/shin
e/WorkSpace/webrtc/src/chromium/src/third_party/android_tools/ndk/toolchains/mip
sel-linux-android-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/mipsel-linux-android/
4.9/libgcc.a -lc -ldl ../../third_party/android_tools/ndk//platforms/android-16/
arch-mips/usr/lib/crtend_android.o
../../third_party/android_tools/ndk//sources/cxx-stl/llvm-libc++/libs/mips/libc+
+_static.a(strtod.o): In function `__hdtoa':
/tmp/ndk-user/tmp/build-libc++/ndk/sources/cxx-stl/llvm-libc++/../../android/sup
port/src/stdio/strtod.c:3112: undefined reference to `__fpclassifyd'
../../third_party/android_tools/ndk//sources/cxx-stl/llvm-libc++/libs/mips/libc+
+_static.a(vfprintf.o): In function `fmt_fp':
/tmp/ndk-user/tmp/build-libc++/ndk/sources/cxx-stl/llvm-libc++/../../android/sup
port/src/stdio/vfprintf.c:242: undefined reference to `__signbit'
/tmp/ndk-user/tmp/build-libc++/ndk/sources/cxx-stl/llvm-libc++/../../android/sup
port/src/stdio/vfprintf.c:250: undefined reference to `__isfinite'
../../third_party/android_tools/ndk//sources/cxx-stl/llvm-libc++/libs/mips/libc+
+_static.a(floatscan.o): In function `hexfloat':
/tmp/ndk-user/tmp/build-libc++/ndk/sources/cxx-stl/llvm-libc++/../../android/sup
port/src/wcstox/floatscan.c:432: undefined reference to `scalbn'
/tmp/ndk-user/tmp/build-libc++/ndk/sources/cxx-stl/llvm-libc++/../../android/sup
port/src/wcstox/floatscan.c:441: undefined reference to `scalbnl'
../../third_party/android_tools/ndk//sources/cxx-stl/llvm-libc++/libs/mips/libc+
+_static.a(floatscan.o): In function `decfloat':
/tmp/ndk-user/tmp/build-libc++/ndk/sources/cxx-stl/llvm-libc++/../../android/sup
port/src/wcstox/floatscan.c:292: undefined reference to `scalbn'
/tmp/ndk-user/tmp/build-libc++/ndk/sources/cxx-stl/llvm-libc++/../../android/sup
port/src/wcstox/floatscan.c:293: undefined reference to `scalbn'
/tmp/ndk-user/tmp/build-libc++/ndk/sources/cxx-stl/llvm-libc++/../../android/sup
port/src/wcstox/floatscan.c:329: undefined reference to `scalbnl'
../../third_party/android_tools/ndk//sources/cxx-stl/llvm-libc++/libs/mips/libc+
+_static.a(math_support.o): In function `fmodl':
/tmp/ndk-user/tmp/build-libc++/ndk/sources/cxx-stl/llvm-libc++/../../android/sup
port/src/math_support.c:61: undefined reference to `fmod'
collect2: error: ld returned 1 exit status
[2878/3843] CXX obj/webrtc/common_vide..._unittests.i420_video_frame_unittest.o
ninja: build stopped: subcommand failed.
大意就是在编译audio_device_tests模块的时候,报找不到fmod函数的错误,通过查找原因,是因为:源码目录\out\Debug\obj\webrtc\modules\audio_device_tests.ninja里配置-lm -lc++_static这两个库的前后顺序错了,将这两个库的位置对调一下就可以编译通过了,但是会有很多个模块都报这个错,一个一个改ninja文件不太可取。
那么接下来就是修改生成ninja文件的脚本,通过搜索,发现是在:源码目录\chromium\src\build\common.gypi里的4819行,将 '-l<(android_libcpp_library)' 修改为 '-l<(android_libcpp_library) -lm'即可。
结果如下:
修改完后,再从步骤2开始运行即可。
Ubuntu 14.04编译WebRTC For Android代码:http://www.linuxdiyf.com/linux/2792.html
Ubuntu下搭建MIPS交叉编译环境:http://www.linuxdiyf.com/linux/3093.html