1. 程式人生 > >licode學習之編譯篇--4

licode學習之編譯篇--4

在上一篇中,編譯gcc,遭遇錯誤

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

使用vim命令,檢視一下這個檔案第7行是啥

[[email protected] 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
[[email protected] gcc-4.8.5]# ls /usr/include/gnu
libc-version.h  lib-names.h  stubs-64
.h stubs.h

看目錄裡面只有stubs-64.h,看這個樣子應該是需要有_WORDSIZE巨集的值為64才可以

[[email protected] 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裡面,沒有找到能啟動這個巨集的定義,新增到環境變數裡面

[[email protected] 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__ @[email protected]
[[email protected] gcc-4.8.5]# ./configure
[[email protected] gcc-4.8.5]# make clean
[[email protected] 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[email protected] gcc-4.8.5]# ./configure --enable-languages=c,c++ --disable-multilib
[[email protected] gcc-4.8.5]# make -j4
[[email protected] gcc-4.8.5]# make install
[[email protected] 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.

[[email protected] 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.
[[email protected] gcc-4.8.5]# cp /usr/bin/gcc /usr/bin/gcc_old
[[email protected] gcc-4.8.5]# cp /usr/bin/g++ /usr/bin/g++_old
[[email protected] gcc-4.8.5]# rm /usr/bin/gcc
[[email protected] gcc-4.8.5]# rm /usr/bin/g++
[[email protected] gcc-4.8.5]# ln -s /usr/local/bin/gcc /usr/bin/gcc
[[email protected] gcc-4.8.5]# ln -s /usr/local/bin/g++ /usr/bin/g++

  [[email protected] erizo]# cp /usr/bin/c++ /usr/bin/c++_old
  [[email protected] erizo]# rm -rf /usr/bin/c++
  [[email protected] erizo]# ln -s /usr/local/bin/c++ /usr/bin/c++

[[email protected] 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.

[[email protected] 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++程式碼

[[email protected] 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
[[email protected] 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",
[[email protected] 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比較低,看來問題可能還不少呢

[[email protected] 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);
        }
[[email protected] 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;

[[email protected] 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_);
[[email protected] erizo]# vim src/erizo/MediaDefinitions.h 
#include <string.h>
[[email protected] 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

[[email protected] 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不支援的程式碼

[[email protected] 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的相容問題

[[email protected] 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));
[[email protected] 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找不到

 

幸運的是,經過不懈的努力,終於能夠正常編譯出來了。