licode学习之编译篇--4

在上一篇中,编译gcc,遭遇错误

/usr/include/gnu/stubs.h:7:27: fatal error: gnu/stubs-32.h: No such file or directory

使用vim命令,查看一下这个文件第7行是啥

[root@localhost gcc-4.8.5]# vim /usr/include/gnu/stubs.h
/* This file selects the right generated file of `__stub_FUNCTION' macros
   based on the architecture being compiled for.  */

#include <bits/wordsize.h>

#if __WORDSIZE == 32
# include <gnu/stubs-32.h>
#elif __WORDSIZE == 64
# include <gnu/stubs-64.h>
#else
# error "unexpected value for __WORDSIZE macro"
#endif
[root@localhost gcc-4.8.5]# ls /usr/include/gnu
libc-version.h  lib-names.h  stubs-64.h  stubs.h

看目录里面只有stubs-64.h,看这个样子应该是需要有_WORDSIZE宏的值为64才可以

[root@localhost gcc-4.8.5]# vim /usr/include/bits/wordsize.h
/* Determine the wordsize from the preprocessor defines.  */

#if defined __x86_64__
# define __WORDSIZE     64
# define __WORDSIZE_COMPAT32    1
#else
# define __WORDSIZE     32
#endif

需要定义 __x86_64__宏,在configure --help里面,没有找到能启动这个宏的定义,添加到环境变量里面

[root@localhost gcc-4.8.5]# vim gcc/Makefile.in
# IN_GCC distinguishes between code compiled into GCC itself and other
# programs built during a bootstrap.
# autoconf inserts -DCROSS_DIRECTORY_STRUCTURE if we are building a
# cross compiler which does not use the native headers and libraries.
INTERNAL_CFLAGS = -DIN_GCC -D__x86_64__ @CROSS@
[root@localhost gcc-4.8.5]# ./configure
[root@localhost gcc-4.8.5]# make clean
[root@localhost gcc-4.8.5]# make
/home/test/log4cxx/gcc-4.8.5/host-x86_64-unknown-linux-gnu/gcc/xgcc -B/home/test/log4cxx/gcc-4.8.5/host-x86_64-unknown-linux-gnu/gcc/ -B/usr/local/x86_64-unknown-linux-gnu/bin/ -B/usr/local/x86_64-unknown-linux-gnu/lib/ -isystem /usr/local/x86_64-unknown-linux-gnu/include -isystem /usr/local/x86_64-unknown-linux-gnu/sys-include    -g -O2 -m32 -O2  -g -O2 -DIN_GCC -D__x86_64__   -W -Wall -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition  -isystem ./include   -fpic -mlong-double-80 -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector   -fpic -mlong-double-80 -I. -I. -I../../../host-x86_64-unknown-linux-gnu/gcc -I../../.././libgcc -I../../.././libgcc/. -I../../.././libgcc/../gcc -I../../.././libgcc/../include -I../../.././libgcc/config/libbid -DENABLE_DECIMAL_BID_FORMAT -DHAVE_CC_TLS  -DUSE_TLS -o _muldi3.o -MT _muldi3.o -MD -MP -MF _muldi3.dep -DL_muldi3 -c ../../.././libgcc/libgcc2.c -fvisibility=hidden -DHIDE_EXPORTS
In file included from ../../.././libgcc/libgcc2.c:56:0:
../../.././libgcc/libgcc2.h:137:1: error: unable to emulate ‘TI’
 typedef   int TItype __attribute__ ((mode (TI)));
 ^
../../.././libgcc/libgcc2.h:138:1: error: unable to emulate ‘TI’
 typedef unsigned int UTItype __attribute__ ((mode (TI)));

坑还真是不少,看样子走的路子可能不太正确

通过百度搜索,https://blog.csdn.net/youfuchen/article/details/11056993?utm_source=blogxgwz6 这个里面使用了新的configure参数,实验一下

[root@localhost gcc-4.8.5]# ./configure --enable-languages=c,c++ --disable-multilib
[root@localhost gcc-4.8.5]# make -j4
[root@localhost gcc-4.8.5]# make install
[root@localhost gcc-4.8.5]# /usr/local/bin/gcc --version
gcc (GCC) 4.8.5
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root@localhost gcc-4.8.5]# /usr/local/bin/g++ --version
g++ (GCC) 4.8.5
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[root@localhost gcc-4.8.5]# cp /usr/bin/gcc /usr/bin/gcc_old
[root@localhost gcc-4.8.5]# cp /usr/bin/g++ /usr/bin/g++_old
[root@localhost gcc-4.8.5]# rm /usr/bin/gcc
[root@localhost gcc-4.8.5]# rm /usr/bin/g++
[root@localhost gcc-4.8.5]# ln -s /usr/local/bin/gcc /usr/bin/gcc
[root@localhost gcc-4.8.5]# ln -s /usr/local/bin/g++ /usr/bin/g++

  [root@localhost erizo]# cp /usr/bin/c++ /usr/bin/c++_old
  [root@localhost erizo]# rm -rf /usr/bin/c++
  [root@localhost erizo]# ln -s /usr/local/bin/c++ /usr/bin/c++

[root@localhost gcc-4.8.5]# gcc --version
gcc (GCC) 4.8.5
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root@localhost gcc-4.8.5]# g++ --version
g++ (GCC) 4.8.5
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

OK,gcc新版本安装完成

回到目录,继续编译licode的c++代码

[root@localhost erizo]# ./buildProject.sh
/home/test/licode-master/erizo/src/third_party/webrtc/src/webrtc/base/event_tracer.cc:169:31: error: expected ‘)’ before ‘PRIu64’
                 ", \"ts\": %" PRIu64
[root@localhost erizo]# vim src/third_party/webrtc/src/webrtc/base/event_tracer.cc
        fprintf(output_file_,
                "%s{ \"name\": \"%s\""
                ", \"cat\": \"%s\""
                ", \"ph\": \"%c\""
                ", \"ts\": %PRIu64\"" //modify as this
                ", \"pid\": %d"
#if defined(WEBRTC_WIN)
                ", \"tid\": %lu"
#else
                ", \"tid\": %d"
#endif  // defined(WEBRTC_WIN)
                "%s"
                "}\n",
[root@localhost erizo]# ./buildProject.sh
In file included from /usr/include/boost/thread/pthread/mutex.hpp:11:0,
                 from /usr/include/boost/thread/mutex.hpp:16,
                 from /usr/include/boost/thread/pthread/thread_data.hpp:12,
                 from /usr/include/boost/thread/thread.hpp:17,
                 from /usr/include/boost/thread.hpp:13,
                 from /home/test/licode-master/erizo/src/erizo/dtls/DtlsClient.cpp:7:
/usr/include/boost/thread/locks.hpp: In instantiation of ‘boost::unique_lock<Mutex>& boost::unique_lock<Mutex>::operator=(boost::unique_lock<Mutex>&&) [with Mutex = boost::mutex]’:
/usr/include/boost/thread/future.hpp:414:33:   required from here
/usr/include/boost/thread/locks.hpp:269:22: error: cannot bind ‘boost::unique_lock<boost::mutex>’ lvalue to ‘boost::unique_lock<boost::mutex>&&’
             swap(temp);
                      ^
/usr/include/boost/thread/locks.hpp:279:14: error:   initializing argument 1 of ‘void boost::unique_lock<Mutex>::swap(boost::unique_lock<Mutex>&&) [with Mutex = boost::mutex]’
         void swap(unique_lock&& other)

这个版本的boost比较低,看来问题可能还不少呢

[root@localhost erizo]# vim /usr/include/boost/thread/locks.hpp
        void swap(unique_lock& other)//modify rvalue to lvale. make "&&" to "&"
        {
            std::swap(m,other.m);
            std::swap(is_locked,other.is_locked);
        }
[root@localhost erizo]# ./buildProject.sh
/home/test/licode-master/erizo/src/erizo/media/ExternalOutput.cpp:38:3: error: ‘void av_register_all()’ is deprecated (declared at /home/test/licode-master/erizo/src/../../build/libdeps/build/include/libavformat/avformat.h:2043) [-Werror=deprecated-declarations]
   av_register_all();

看来ffmpeg的版本比较高,不兼容啊,注释掉av_register_all,忽略他。

context_->filename改为context_->url,将->codec改为->codecpar,注释掉av_codec_close,将codecpar->pix_fmt修改为codecpar->format, 将 PIX_FMT_YUV420P修改为AV_PIX_FMT_YUV420P;注释掉->codecpar->flags |= CODEC_FLAG_GLOBAL_HEADER;

[root@localhost erizo]# ./buildProject.sh 
In file included from /home/test/licode-master/erizo/src/erizo/media/SyntheticInput.h:8:0,
                 from /home/test/licode-master/erizo/src/erizo/media/SyntheticInput.cpp:1:
/home/test/licode-master/erizo/src/erizo/./MediaDefinitions.h: In constructor ‘erizo::DataPacket::DataPacket(int, const char*, int, erizo::packetType, uint64_t)’:
/home/test/licode-master/erizo/src/erizo/./MediaDefinitions.h:28:34: error: ‘memcpy’ was not declared in this scope
       memcpy(data, data_, length_);
[root@localhost erizo]# vim src/erizo/MediaDefinitions.h 
#include <string.h>
[root@localhost erizo]# ./buildProject.sh
/home/test/licode-master/erizo/src/erizo/media/codecs/VideoCodec.cpp: In constructor ‘erizo::VideoEncoder::VideoEncoder()’:
/home/test/licode-master/erizo/src/erizo/media/codecs/VideoCodec.cpp:27:3: error: ‘void avcodec_register_all()’ is deprecated (declared at /home/test/licode-master/erizo/src/../../build/libdeps/build/include/libavcodec/avcodec.h:4119) [-Werror=deprecated-declarations]
   avcodec_register_all();

有一个ffmpeg兼容问题,修改源码,兼容新版本ffmpeg

[root@localhost erizo]# vim src/erizo/media/codecs/VideoCodec.cpp
  //ret = avcodec_encode_video2(vCoderContext, &pkt, cPicture, &got_packet);
  ret = avcodec_send_frame(vCoderContext, cPicture);
  got_packet = !avcodec_receive_packet(vCoderContext, &pkt);

还得注释掉,新版本ffmpeg不支持的代码

[root@localhost erizo]# ./buildProject.sh 
/home/test/licode-master/erizo/src/../../build/libdeps/build/include/libavutil/common.h:30:2: error: #error missing -D__STDC_CONSTANT_MACROS / #define __STDC_CONSTANT_MACROS
 #error missing -D__STDC_CONSTANT_MACROS / #define __STDC_CONSTANT_MACROS

这个错误不是ffmpeg的兼容问题,是一个宏没有定义。

因为只是在linux上面使用这些头文件,直接将之定义在libavutil/common.h里面。之后继续修改ffmpeg的兼容问题

[root@localhost erizo]# ./buildProject.sh 
/home/test/licode-master/erizo/src/erizo/SrtpChannel.cpp: In member function ‘bool erizo::SrtpChannel::configureSrtpSession(srtp_ctx_t**, const string&, erizo::SrtpChannel::TransmissionType)’:
/home/test/licode-master/erizo/src/erizo/SrtpChannel.cpp:152:36: error: ‘memset’ was not declared in this scope
   memset(&policy, 0, sizeof(policy));
[root@localhost erizo]# vim src/erizo/SrtpChannel.cpp

/*
 * Srtpchannel.cpp
 */
#include <string.h> //add this line
#include <srtp2/srtp.h>
#include <nice/nice.h>

#include <string>

#include "SrtpChannel.h"

继续编译,还会报test里面的boost的错误,在报错cpp的文件最前面加上 #include <boost/thread/thread.hpp>

还会遇到前面遇到的错误,是因为编译完成debug版本后,还会再次编译release版本,产生错误,修改之,让其正确

编译过程真是巨慢。。。。。。。。。

OK,终于编译完成了。

 

在最后,总结一下编译的过程。

1、需要一些开源库,并没有自动下载编译,比如ffmpeg

2、yum下来的开发版本软件错误,比如boost的头文件的代码错误

3、gcc版本不兼容,这个可真是天坑。configure的参数还得再仔细研究一下

4、ffmpeg新老版本兼容问题,也是一个比较大的坑

5、开源库的一些头文件缺少标准库文件,比如<stdio.h> <string.h>,没有引用,导致找不到符号。也行在ubuntu上正常,我就没有试验了

6、在c文件中,中间位置定义变量,尤其是在for里面定义变量,导致编译错误。

7、找不到库的提示信息比较不完善,必须翻看编译脚本源码才能知道,比如LOG_NOTFOUNT,如果不看源码,根本不知道是log4cxx找不到

 

幸运的是,经过不懈的努力,终于能够正常编译出来了。

 

posted @ 2018-11-29 17:13  media_myself  阅读(1695)  评论(0编辑  收藏  举报