让自己的vs工程能够使用webrtc库

总述

1、采用的代码是 /69   2018-0816-0156 的版本,vs是2017

 

 

A 、首先webrtc编译大致流程:
1、gn 生成工程文件

2、ninja调用相关的编译器实现编译

所以为了让自己编译出来的webrtc库能够被自己的vs工程使用关键是gn生成工程文件的地方。

webrtc默认的编译器是clang. 通过她编译出来的lib有时候我们的vs工程用不了会报如下错误:

webrtc.lib : fatal error LNK1136: invalid or corrupt file(只是举个例子)

所以在使用gn生成工程文件的时候需要带上  “is_clang=false ” 这样的参数。例如:

gn gen --ide=vs out/Debug --args="target_winuwp_version=\"8.1\" target_winuwp_family=\"desktop\" use_rtti=true is_clang=false is_component_ffmpeg=false"   (https://groups.google.com/forum/#!topic/discuss-webrtc/9CjnkJ8QVXc)

 

去掉单元测试的命令

gn gen --ide=vs out/Debug --args="target_winuwp_version=\"8.1\" target_winuwp_family=\"desktop\" use_rtti=true is_clang=false libyuv_include_tests=false rtc_include_tests=false libyuv_include_tests=true rtc_use_h264=true"

B、如何使用编译生成的库

我们需要相应的lib文件和头文件

需要注意的是头文件和lib文件相对路径必须要正确,所以我们在复制头文件和lib的时候要保证他们的目录结构没有改变,以下命令可以帮组我们

以上是复制头文件的例子,自己可以变通一下修改成复制lib文件的例子。

C、如何搭建自己的工程

 有了头文件有了库文件,那么就开始来搭建我们自己的vs工程吧!!!

以webrtc自带的peernnection_client为例,首先来看我工程接口截图

 

1、自己创建一个窗口工程名字自己随便写(不详述)

2、把 webrtc-code\src\examples\peerconnection\client 把这个目录下的代码放到步骤1中创建的工程中,并引用

3、把之前复制的头文件和lib文件的引用基本路径设置到你的工程用,

4、为项目设置相关的宏

应用webrtc库需要的宏一般只有三个:NOMINMAX  WIN32_LEAN_AND_MEAN WEBRTC_WIN

但是如果在之后的过程中仍然编译不过,那么就把peerconnection_client.ninja中涉及到的所有宏都设置到工程里面。

5、为项目添加lib,因为lib很多我就不详述了,直接列出来(一下只是webrtc相关的lib)

#pragma comment(lib, "obj/third_party/boringssl/boringssl.lib")

#pragma comment(lib, "obj/third_party/boringssl/boringssl_asm.lib")

#pragma comment(lib, "obj/third_party/libjpeg_turbo/libjpeg.lib")

#pragma comment(lib, "obj/third_party/libjpeg_turbo/simd.lib")

#pragma comment(lib, "obj/third_party/libjpeg_turbo/simd_asm.lib")

#pragma comment(lib, "obj/third_party/libsrtp/libsrtp.lib")

#pragma comment(lib, "obj/third_party/libvpx/libvpx.lib")

#pragma comment(lib, "obj/third_party/libvpx/libvpx_yasm.lib")

#pragma comment(lib, "obj/third_party/libyuv/libyuv_internal.lib")

//#pragma comment(lib, "obj/third_party/openmax_dl/dl/dl.lib")

#pragma comment(lib, "obj/third_party/opus/opus.lib")

#pragma comment(lib, "obj/third_party/protobuf/protobuf_lite.lib")

#pragma comment(lib, "obj/third_party/usrsctp/usrsctp.lib")

#pragma comment(lib, "obj/third_party/winsdk_samples/winsdk_samples.lib")

#pragma comment(lib, "obj/api/audio_codecs/builtin_audio_decoder_factory.lib")

#pragma comment(lib, "obj/api/audio_codecs/builtin_audio_encoder_factory.lib")

#pragma comment(lib, "obj/api/audio_codecs/opus/audio_encoder_opus_config.lib")

#pragma comment(lib, "obj/api/libjingle_peerconnection_api.lib")

#pragma comment(lib, "obj/audio/audio.lib")

#pragma comment(lib, "obj/audio/utility/audio_frame_operations.lib")

#pragma comment(lib, "obj/call/call.lib")

#pragma comment(lib, "obj/common_audio/common_audio.lib")

#pragma comment(lib, "obj/common_audio/common_audio_sse2.lib")

#pragma comment(lib, "obj/common_video/common_video.lib")

#pragma comment(lib, "obj/logging/rtc_event_log_impl_base.lib")

#pragma comment(lib, "obj/logging/rtc_event_log_impl_encoder.lib")

#pragma comment(lib, "obj/logging/rtc_event_log_proto.lib")

#pragma comment(lib, "obj/media/rtc_audio_video.lib")

#pragma comment(lib, "obj/media/rtc_data.lib")

#pragma comment(lib, "obj/media/rtc_media_base.lib")

#pragma comment(lib, "obj/modules/audio_coding/ana_config_proto.lib")

#pragma comment(lib, "obj/modules/audio_coding/ana_debug_dump_proto.lib")

#pragma comment(lib, "obj/modules/audio_coding/audio_coding.lib")

#pragma comment(lib, "obj/modules/audio_coding/audio_format_conversion.lib")

#pragma comment(lib, "obj/modules/audio_coding/audio_network_adaptor.lib")

#pragma comment(lib, "obj/api/libjingle_peerconnection_api.lib")

#pragma comment(lib, "obj/api/audio_codecs/builtin_audio_decoder_factory.lib")

#pragma comment(lib, "obj/api/audio_codecs/builtin_audio_encoder_factory.lib")

#pragma comment(lib, "obj/api/audio_codecs/g711/audio_decoder_g711.lib")

#pragma comment(lib, "obj/api/audio_codecs/g711/audio_encoder_g711.lib")

#pragma comment(lib, "obj/api/audio_codecs/g722/audio_decoder_g722.lib")

#pragma comment(lib, "obj/api/audio_codecs/g722/audio_encoder_g722.lib")

#pragma comment(lib, "obj/api/audio_codecs/ilbc/audio_decoder_ilbc.lib")

#pragma comment(lib, "obj/api/audio_codecs/ilbc/audio_encoder_ilbc.lib")

#pragma comment(lib, "obj/api/audio_codecs/isac/audio_decoder_isac_float.lib")

#pragma comment(lib, "obj/api/audio_codecs/isac/audio_encoder_isac_float.lib")

#pragma comment(lib, "obj/api/audio_codecs/L16/audio_decoder_L16.lib")

#pragma comment(lib, "obj/api/audio_codecs/L16/audio_encoder_L16.lib")

#pragma comment(lib, "obj/api/audio_codecs/opus/audio_decoder_opus.lib")

#pragma comment(lib, "obj/api/audio_codecs/opus/audio_encoder_opus_config.lib")

#pragma comment(lib, "obj/modules/audio_coding/isac_common.lib")

#pragma comment(lib, "obj/modules/audio_coding/legacy_encoded_audio_frame.lib")

#pragma comment(lib, "obj/modules/audio_coding/neteq.lib")

#pragma comment(lib, "obj/modules/audio_coding/pcm16b.lib")

#pragma comment(lib, "obj/modules/audio_coding/red.lib")

#pragma comment(lib, "obj/modules/audio_coding/rent_a_codec.lib")

#pragma comment(lib, "obj/modules/audio_coding/webrtc_opus.lib")

//#pragma comment(lib, "obj/modules/audio_conference_mixer/audio_conference_mixer.lib")

//#pragma comment(lib, "obj/modules/audio_device/audio_device.lib")

#pragma comment(lib, "obj/modules/audio_mixer/audio_frame_manipulator.lib")

#pragma comment(lib, "obj/modules/audio_mixer/audio_mixer_impl.lib")

#pragma comment(lib, "obj/modules/audio_processing/audio_processing.lib")

//#pragma comment(lib, "obj/modules/audio_processing/audio_processing_sse2.lib")

#pragma comment(lib, "obj/modules/audio_processing/audioproc_debug_proto.lib")

#pragma comment(lib, "obj/modules/bitrate_controller/bitrate_controller.lib")

#pragma comment(lib, "obj/modules/congestion_controller/congestion_controller.lib")

#pragma comment(lib, "obj/media/rtc_media_base.lib")

#pragma comment(lib, "obj/modules/pacing/pacing.lib")

#pragma comment(lib, "obj/modules/remote_bitrate_estimator/remote_bitrate_estimator.lib")

#pragma comment(lib, "obj/modules/rtp_rtcp/rtp_rtcp.lib")

#pragma comment(lib, "obj/modules/utility/utility.lib")

#pragma comment(lib, "obj/modules/video_capture/video_capture_module.lib")

#pragma comment(lib, "obj/modules/video_coding/video_coding.lib")

#pragma comment(lib, "obj/modules/video_coding/webrtc_h264.lib")

#pragma comment(lib, "obj/modules/video_coding/webrtc_vp8.lib")

#pragma comment(lib, "obj/modules/video_coding/webrtc_vp9.lib")

#pragma comment(lib, "obj/modules/video_processing/video_processing.lib")

#pragma comment(lib, "obj/modules/video_processing/video_processing_sse2.lib")

#pragma comment(lib, "obj/p2p/libstunprober.lib")

#pragma comment(lib, "obj/p2p/rtc_p2p.lib")

#pragma comment(lib, "obj/pc/create_pc_factory.lib")

#pragma comment(lib, "obj/pc/peerconnection.lib")

#pragma comment(lib, "obj/pc/rtc_pc_base.lib")

#pragma comment(lib, "obj/rtc_base/rtc_base.lib")

#pragma comment(lib, "obj/rtc_base/rtc_numerics.lib")

#pragma comment(lib, "obj/rtc_base/weak_ptr.lib")

#pragma comment(lib, "obj/stats/rtc_stats.lib")

#pragma comment(lib, "obj/system_wrappers/system_wrappers.lib")

#pragma comment(lib, "obj/video/video.lib")

#pragma comment(lib, "obj/webrtc.lib")

 

6、设置windows自带的库

dbghelp.lib
dnsapi.lib
msimg32.lib
psapi.lib
shlwapi.lib
usp10.lib
version.lib
wininet.lib
winmm.lib
ws2_32.lib
delayimp.lib
crypt32.lib
iphlpapi.lib
secur32.lib
dmoguids.lib
wmcodecdspuuid.lib
amstrmid.lib
msdmo.lib
strmiids.lib

7、编译

到这一步时语法错误和连接错误都应该已经没有了。

 

posted @ 2018-09-14 17:12  无名状  阅读(5672)  评论(1编辑  收藏  举报