1、首先下载janue源代码:
git clone https://github.com/meetecho/janus-gateway
2、安装依赖项
brew install jansson libnice openssl srtp libusrsctp libmicrohttpd \
libwebsockets cmake rabbitmq-c sofia-sip opus libogg curl glib \
libconfig pkg-config gengetopt autoconf automake libtool
#建议安装后再升级下
brew upgrade jansson libnice openssl srtp libusrsctp libmicrohttpd \
libwebsockets cmake rabbitmq-c sofia-sip opus libogg curl glib \
libconfig pkg-config gengetopt autoconf automake libtool
3、生成configure文件
./autogen.sh
4、configure
#按照官方指导配置
./configure --prefix=/usr/local/janus \
PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig
但是发现失败:
checking pkg-config is at least version 0.9.0... yes
checking for
glib-2.0 >= 2.34
libconfig
nice
jansson >= 2.5
libssl >= 1.0.1
libcrypto
... no
configure: error: Package requirements (
glib-2.0 >= 2.34
libconfig
nice
jansson >= 2.5
libssl >= 1.0.1
libcrypto
) were not met:
Package 'libffi', required by 'gobject-2.0', not found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables JANUS_CFLAGS
and JANUS_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
从错误提示来看,开始以为是第三方依赖版本不匹配,但是通过分析脚本发现,janus是通过pkg-config匹配依赖项,在执行pkg-config查找libnice路径时发现错误:
xzldeMacBook-Pro:janus-gateway xzl$ pkg-config nice --cflags
Package libffi was not found in the pkg-config search path.
Perhaps you should add the directory containing `libffi.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libffi', required by 'gobject-2.0', not found
从错误提示看应该是libffi未安装,但是在 brew install 安装时发现已经存在,于是先卸载再安装:
xzldeMacBook-Pro:janus-gateway xzl$ brew uninstall --ignore-dependencies libffi
Uninstalling /usr/local/Cellar/libffi/3.2.1... (16 files, 296.8KB)
xzldeMacBook-Pro:janus-gateway xzl$ brew install libffi
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/libffi-3.2.1.mojave.bottle.tar.gz
Already downloaded: /Users/xzl/Library/Caches/Homebrew/downloads/89b4ef328be250153e7a2b39982ac446e0b3bbfe7f3e2708912ba1976862c302--libffi-3.2.1.mojave.bottle.tar.gz
==> Pouring libffi-3.2.1.mojave.bottle.tar.gz
==> Caveats
libffi is keg-only, which means it was not symlinked into /usr/local,
because some formulae require a newer version of libffi.
For compilers to find libffi you may need to set:
export LDFLAGS="-L/usr/local/opt/libffi/lib"
For pkg-config to find libffi you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"
==> Summary
🍺 /usr/local/Cellar/libffi/3.2.1: 16 files, 296.8KB
注意这句提示:
For pkg-config to find libffi you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"
所以不难发现 pkg-config默认是找不到libffi的,而libnice依赖libffi,所以我们在查找libnice时应该这样:
export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"
pkg-config nice --cflags
所以我们在执行janus的configure脚本时改成这样:
./configure --prefix=/usr/local/janus \
PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig:/usr/local/opt/libffi/lib/pkgconfig"
然后我们就能配置成功了:
xzldeMacBook-Pro:janus-gateway xzl$ ./configure --prefix=/usr/local/janus \
> PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig:/usr/local/opt/libffi/lib/pkgconfig"
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ./install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking whether make supports the include directive... yes (GNU style)
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking minix/config.h usability... no
checking minix/config.h presence... no
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking for gcc... (cached) gcc
checking whether we are using the GNU C compiler... (cached) yes
checking whether gcc accepts -g... (cached) yes
checking for gcc option to accept ISO C89... (cached) none needed
checking whether gcc understands -c and -o together... (cached) yes
checking dependency style of gcc... (cached) gcc3
checking build system type... x86_64-apple-darwin18.0.0
checking host system type... x86_64-apple-darwin18.0.0
checking how to print strings... printf
checking for a sed that does not truncate output... /usr/bin/sed
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld
checking if the linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) is GNU ld... no
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 196608
checking how to convert x86_64-apple-darwin18.0.0 file names to x86_64-apple-darwin18.0.0 format... func_convert_file_noop
checking how to convert x86_64-apple-darwin18.0.0 file names to toolchain format... func_convert_file_noop
checking for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... no
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /bin/dd
checking how to truncate binary pipes... /bin/dd bs=4096 count=1
checking for mt... no
checking if : is a manifest tool... no
checking for dsymutil... dsymutil
checking for nmedit... nmedit
checking for lipo... lipo
checking for otool... otool
checking for otool64... no
checking for -single_module linker flag... yes
checking for -exported_symbols_list linker flag... yes
checking for -force_load linker flag... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... yes
checking for gcc option to produce PIC... -fno-common -DPIC
checking if gcc PIC flag -fno-common -DPIC works... yes
checking if gcc static flag -static works... no
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... darwin18.0.0 dyld
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
checking for pkg-config... /usr/local/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for
glib-2.0 >= 2.34
libconfig
nice
jansson >= 2.5
libssl >= 1.0.1
libcrypto
... yes
checking for library containing tls_config_set_ca_mem... no
checking for nice_agent_set_port_range in -lnice... yes
checking for nice_address_equal_no_port in -lnice... yes
checking for dlopen in -ldl... yes
checking for srtp_init in -lsrtp2... yes
checking srtp2/srtp.h usability... yes
checking srtp2/srtp.h presence... yes
checking for srtp2/srtp.h... yes
checking for srtp_crypto_policy_set_aes_gcm_256_16_auth in -lsrtp2... no
configure: libsrtp2 does not have support for AES-GCM profiles
checking for usrsctp_finish in -lusrsctp... yes
checking for libcurl... yes
checking for doxygen... no
checking for dot... no
checking for gengetopt... yes
checking for
glib-2.0 >= 2.34
jansson >= 2.5
... yes
checking for libmicrohttpd... yes
checking for lws_create_vhost in -lwebsockets... yes
checking for lws_get_peer_simple in -lwebsockets... yes
checking for amqp_error_string2 in -lrabbitmq... yes
checking for MQTTAsync_create in -lpaho-mqtt3a... no
checking for nn_socket in -lnanomsg... no
checking for
glib-2.0 >= 2.34
jansson >= 2.5
... yes
checking for sofia-sip-ua... yes
checking for libre >= 0.5.7... no
checking for libre... no
checking for opus... yes
checking for ogg... yes
checking for lua... no
checking for lua5.3... no
checking for
glib-2.0 >= 2.34
jansson >= 2.5
... yes
checking for npm... no
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating html/Makefile
config.status: creating docs/Makefile
config.status: executing depfiles commands
config.status: executing libtool commands
Compiler: gcc
libsrtp version: 2.x
SSL/crypto library: OpenSSL
DTLS set-timeout: not available
Mutex implementation: GMutex (native futex on Linux)
DataChannels support: yes
Recordings post-processor: no
TURN REST API client: yes
Doxygen documentation: no
Transports:
REST (HTTP/HTTPS): yes
WebSockets: yes
RabbitMQ: yes
MQTT: no
Unix Sockets: no
Nanomsg: no
Plugins:
Echo Test: yes
Streaming: yes
Video Call: yes
SIP Gateway (Sofia): yes
SIP Gateway (libre): no
NoSIP (RTP Bridge): yes
Audio Bridge: yes
Video Room: yes
Voice Mail: yes
Record&Play: yes
Text Room: yes
Lua Interpreter: no
Duktape Interpreter: no
Event handlers:
Sample event handler: yes
RabbitMQ event handler:yes
MQTT event handler: no
JavaScript modules: no
If this configuration is ok for you, do a 'make' to start building Janus. A 'make install' will install Janus and its plugins to the specified prefix. Finally, a 'make configs' will install some sample configuration files too (something you'll only want to do the first time, though).
5、编译
make -j4
但是链接openssl库发现链接失败:
Undefined symbols for architecture x86_64:
"_CRYPTO_THREADID_set_callback", referenced from:
_janus_dtls_srtp_init in janus-dtls.o
"_CRYPTO_THREADID_set_pointer", referenced from:
_janus_dtls_cb_openssl_threadid in janus-dtls.o
"_CRYPTO_num_locks", referenced from:
_janus_dtls_srtp_init in janus-dtls.o
"_CRYPTO_set_locking_callback", referenced from:
_janus_dtls_srtp_init in janus-dtls.o
"_ERR_free_strings", referenced from:
_main in janus-janus.o
"_EVP_cleanup", referenced from:
_main in janus-janus.o
"_OPENSSL_add_all_algorithms_noconf", referenced from:
_main in janus-janus.o
"_SSL_library_init", referenced from:
_main in janus-janus.o
"_SSL_load_error_strings", referenced from:
_main in janus-janus.o
"_SSL_state", referenced from:
_janus_dtls_srtp_incoming_msg in janus-dtls.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [janus] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
通过执行pkg-config查找openssl库目录:
xzldeMacBook-Pro:janus-gateway xzl$ pkg-config openssl --libs
-L/usr/local/lib -lssl -lcrypto
设置PKG_CONFIG_PATH环境变量后再执行:
xzldeMacBook-Pro:janus-gateway xzl$ export PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig
xzldeMacBook-Pro:janus-gateway xzl$ pkg-config openssl --libs
-L/usr/local/Cellar/openssl/1.0.2r/lib -lssl -lcrypto
可以发现指向的openssl库不一致,联想到笔者前不仅手动安装过openssl,所以系统默认路径下的openssl库应该是笔者之前手动安装的版本,所以在configure时不需要指定openssl的pkg-config配置文件路径,重新配置一遍再编译即可成功:
./configure --prefix=/usr/local/janus \
PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig" \
&& make -j4
测试是否编译成功:
xzldeMacBook-Pro:janus-gateway xzl$ ./janus --version
Janus commit: d0fecb0b4a4c4dc23b3e0a7038970ba382e66620
Compiled on: 2019? 5? 5? ??? 18?26?32? CST
janus 0.7.0
xzldeMacBook-Pro:janus-gateway xzl$