licode学习之编译篇--3
Posted limedia
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了licode学习之编译篇--3相关的知识,希望对你有一定的参考价值。
上一篇中,提示找不到NICE库,先看看CMakList里面吧
[[email protected] erizo]# pwd /home/test/licode-master/erizo [[email protected] erizo]# vim src/CMakeLists.txt #global variable set(THIRD_PARTY_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/../../build/libdeps/build/include/") set(THIRD_PARTY_LIB "${CMAKE_CURRENT_SOURCE_DIR}/../../build/libdeps/build/lib/") ## Depencencies # GLIB find_package(Glib REQUIRED) include_directories(${GLIB_INCLUDE_DIRS}) # BOOST set (BOOST_LIBS thread regex system) find_package(Boost COMPONENTS ${BOOST_LIBS} REQUIRED) # GTHREAD find_library(GTHREAD gthread-2.0 HINTS "${THIRD_PARTY_LIB}") test_lib(${GTHREAD}) # SRTP find_library(SRTP srtp2 HINTS "${THIRD_PARTY_LIB}") test_lib(${SRTP}) # NICE find_library(NICE nice HINTS "${THIRD_PARTY_LIB}") test_lib(${NICE})
看来"${CMAKE_CURRENT_SOURCE_DIR}/../../build/libdeps/build/lib/里面没有nice库
进到目录:
[[email protected] libdeps]# ls build libav-11.9 libnice-0.1.4 libnice-0.1.4.tar.gz libsrtp-2.1.0 libsrtp-2.1.0.tar.gz nvm openssl-1.0.2p openssl-1.0.2p.tar.gz opus-1.1.tar.gz v11.9.tar.gz [[email protected] libdeps]# pwd /home/test/licode-master/build/libdeps [[email protected] libdeps]# ls build/lib/ engines/ libcrypto.a libsrtp2.a libssl.a pkgconfig/
确实是没有nice库,但是nice已经下载了,只是没有编译,对nice进行编译
[[email protected] libnice-0.1.4]# ls aclocal.m4 AUTHORS ChangeLog config.guess config.log configure COPYING COPYING.MPL docs gst INSTALL ltmain.sh Makefile.in NEWS random scripts stun TODO agent autogen.sh common.mk config.h.in config.sub configure.ac COPYING.LGPL depcomp examples gtk-doc.make install-sh Makefile.am missing nice README socket tests win32 [[email protected] libnice-0.1.4]# ./configure --prefix=/home/test/licode-master/build/libdeps/build/ threaded-example.c: In function ‘main’: threaded-example.c:110: warning: implicit declaration of function ‘g_thread_new’ threaded-example.c:110: warning: nested extern declaration of ‘g_thread_new’ threaded-example.c:110: warning: assignment makes pointer from integer without a cast threaded-example.c: At top level: threaded-example.c:53: error: storage size of ‘gather_mutex’ isn’t known threaded-example.c:53: error: storage size of ‘negotiate_mutex’ isn’t known threaded-example.c:54: error: storage size of ‘gather_cond’ isn’t known threaded-example.c:54: error: storage size of ‘negotiate_cond’ isn’t known
make错误,得先解决一下这个符号错误,看看53行
[[email protected] libnice-0.1.4]# vim examples/threaded-example.c
static GMutex gather_mutex, negotiate_mutex; static GCond gather_cond, negotiate_cond;
很简单的定义代码,但是说不认识这个结构,令人费解了
看看GMutex定义,看看有没有结构吧
[[email protected] libnice-0.1.4]# vim /usr/include/glib-2.0/glib/gthread.h typedef struct _GMutex GMutex; typedef struct _GCond GCond; typedef struct _GPrivate GPrivate; typedef struct _GStaticPrivate GStaticPrivate; typedef struct _GThreadFunctions GThreadFunctions; struct _GThreadFunctions { GMutex* (*mutex_new) (void); void (*mutex_lock) (GMutex *mutex); gboolean (*mutex_trylock) (GMutex *mutex); void (*mutex_unlock) (GMutex *mutex); void (*mutex_free) (GMutex *mutex); GCond* (*cond_new) (void); void (*cond_signal) (GCond *cond); void (*cond_broadcast) (GCond *cond); void (*cond_wait) (GCond *cond, GMutex *mutex); gboolean (*cond_timed_wait) (GCond *cond, GMutex *mutex, GTimeVal *end_time); void (*cond_free) (GCond *cond); GPrivate* (*private_new) (GDestroyNotify destructor); gpointer (*private_get) (GPrivate *private_key); void (*private_set) (GPrivate *private_key, gpointer data); void (*thread_create) (GThreadFunc func, gpointer data, gulong stack_size, gboolean joinable, gboolean bound, GThreadPriority priority, gpointer thread, GError **error); void (*thread_yield) (void); void (*thread_join) (gpointer thread); void (*thread_exit) (void); void (*thread_set_priority)(gpointer thread, GThreadPriority priority); void (*thread_self) (gpointer thread); gboolean (*thread_equal) (gpointer thread1, gpointer thread2); }; GLIB_VAR GThreadFunctions g_thread_functions_for_glib_use; GLIB_VAR gboolean g_thread_use_default_impl; GLIB_VAR gboolean g_threads_got_initialized;
看这个样子,是这个版本的glib并不支持GMutex结构体,而改为函数调用,并且提供默认管理以及外部处理管理。
目前我们只需要让example编译通过,直接使用默认的即可。
将threaded_example.c修改为:
1 /* 2 * Copyright 2013 University of Chicago 3 * Contact: Bryce Allen 4 * Copyright 2013 Collabora Ltd. 5 * Contact: Youness Alaoui 6 * 7 * The contents of this file are subject to the Mozilla Public License Version 8 * 1.1 (the "License"); you may not use this file except in compliance with 9 * the License. You may obtain a copy of the License at 10 * http://www.mozilla.org/MPL/ 11 * 12 * Software distributed under the License is distributed on an "AS IS" basis, 13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 14 * for the specific language governing rights and limitations under the 15 * License. 16 * 17 * Alternatively, the contents of this file may be used under the terms of the 18 * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which 19 * case the provisions of LGPL are applicable instead of those above. If you 20 * wish to allow use of your version of this file only under the terms of the 21 * LGPL and not to allow others to use your version of this file under the 22 * MPL, indicate your decision by deleting the provisions above and replace 23 * them with the notice and other provisions required by the LGPL. If you do 24 * not delete the provisions above, a recipient may use your version of this 25 * file under either the MPL or the LGPL. 26 */ 27 28 /* 29 * Example using libnice to negotiate a UDP connection between two clients, 30 * possibly on the same network or behind different NATs and/or stateful 31 * firewalls. 32 * 33 * Build: 34 * gcc -o threaded-example threaded-example.c `pkg-config --cflags --libs nice` 35 * 36 * Run two clients, one controlling and one controlled: 37 * threaded-example 0 $(host -4 -t A stun.stunprotocol.org | awk ‘{ print $4 }‘) 38 * threaded-example 1 $(host -4 -t A stun.stunprotocol.org | awk ‘{ print $4 }‘) 39 */ 40 #include <stdlib.h> 41 #include <stdio.h> 42 #include <string.h> 43 #include <ctype.h> 44 #include <unistd.h> 45 46 #include <agent.h> 47 48 static GMainLoop *gloop; 49 static gchar *stun_addr = NULL; 50 static guint stun_port; 51 static gboolean controlling; 52 static gboolean exit_thread, candidate_gathering_done, negotiation_done; 53 static GMutex* gather_mutex = NULL, *negotiate_mutex = NULL;//modify use pointer 54 static GCond* gather_cond = NULL, *negotiate_cond = NULL;//modify use pointer 55 56 static const gchar *candidate_type_name[] = {"host", "srflx", "prflx", "relay"}; 57 58 static const gchar *state_name[] = {"disconnected", "gathering", "connecting", 59 "connected", "ready", "failed"}; 60 61 static int print_local_data(NiceAgent *agent, guint stream_id, 62 guint component_id); 63 static int parse_remote_data(NiceAgent *agent, guint stream_id, 64 guint component_id, char *line); 65 static void cb_candidate_gathering_done(NiceAgent *agent, guint stream_id, 66 gpointer data); 67 static void cb_new_selected_pair(NiceAgent *agent, guint stream_id, 68 guint component_id, gchar *lfoundation, 69 gchar *rfoundation, gpointer data); 70 static void cb_component_state_changed(NiceAgent *agent, guint stream_id, 71 guint component_id, guint state, 72 gpointer data); 73 static void cb_nice_recv(NiceAgent *agent, guint stream_id, guint component_id, 74 guint len, gchar *buf, gpointer data); 75 76 static void * example_thread(void *data); 77 78 int 79 main(int argc, char *argv[]) 80 { 81 82 gather_mutex = g_mutex_new(); 83 negotiate_mutex = g_mutex_new(); 84 gather_cond = g_cond_new(); 85 negotiate_cond = g_cond_new(); 86 GThread *gexamplethread; 87 88 // Parse arguments 89 if (argc > 4 || argc < 2 || argv[1][1] != ‘