在centos7上从源代码编译gcc4.9.2

compile gcc4.9.2 from source on centos7

我想用densepose,根据安装需要安装gcc4.9.2。 我已经下载了 gcc-4.9.2.tar.gz 和先决条件。 然后运行配置

../gcc-4.9.2/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib

这里是配置结果

checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln works... yes
checking whether ln -s works... yes
checking for a sed that does not truncate output... /usr/bin/sed
checking for gawk... gawk
checking for libatomic support... yes
checking for libcilkrts support... yes
checking for libitm support... yes
checking for libsanitizer support... yes
checking for libvtv support... yes
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
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 for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking whether g++ accepts -static-libstdc++ -static-libgcc... no
checking for gnatbind... no
checking for gnatmake... no
checking whether compiler driver understands Ada... no
checking how to compare bootstrapped objects... cmp --ignore-initial=16 $$f1 $$f2
checking for objdir... .libs
configure: WARNING: using in-tree ISL, disabling version check
configure: WARNING: using in-tree CLooG, disabling version check
*** This configuration is not supported in the following subdirectories:
     gnattools target-libada target-libgfortran target-libgo target-libffi target-libbacktrace target-zlib target-libjava target-libobjc target-boehm-gc
    (Any other directories should still work fine.)
checking for default BUILD_CONFIG... bootstrap-debug
checking for --enable-vtable-verify... no
checking for bison... bison -y
checking for bison... bison
checking for gm4... no
checking for gnum4... no
checking for m4... m4
checking for flex... flex
checking for flex... flex
checking for makeinfo... no
checking for expect... no
checking for runtest... no
checking for ar... ar
checking for as... as
checking for dlltool... no
checking for ld... ld
checking for lipo... no
checking for nm... nm
checking for ranlib... ranlib
checking for strip... strip
checking for windres... no
checking for windmc... no
checking for objcopy... objcopy
checking for objdump... objdump
checking for readelf... readelf
checking for cc... cc
checking for c++... c++
checking for gcc... gcc
checking for gcj... no
checking for gfortran... gfortran
checking for gccgo... no
checking for ar... no
checking for ar... ar
checking for as... no
checking for as... as
checking for dlltool... no
checking for dlltool... no
checking for ld... no
checking for ld... ld
checking for lipo... no
checking for lipo... no
checking for nm... no
checking for nm... nm
checking for objdump... no
checking for objdump... objdump
checking for ranlib... no
checking for ranlib... ranlib
checking for readelf... no
checking for readelf... readelf
checking for strip... no
checking for strip... strip
checking for windres... no
checking for windres... no
checking for windmc... no
checking for windmc... no
checking where to find the target ar... host tool
checking where to find the target as... host tool
checking where to find the target cc... just compiled
checking where to find the target c++... just compiled
checking where to find the target c++ for libstdc++... just compiled
checking where to find the target dlltool... host tool
checking where to find the target gcc... just compiled
checking where to find the target gcj... host tool
checking where to find the target gfortran... host tool
checking where to find the target gccgo... host tool
checking where to find the target ld... host tool
checking where to find the target lipo... host tool
checking where to find the target nm... host tool
checking where to find the target objdump... host tool
checking where to find the target ranlib... host tool
checking where to find the target readelf... host tool
checking where to find the target strip... host tool
checking where to find the target windres... host tool
checking where to find the target windmc... host tool
checking whether to enable maintainer-specific portions of Makefiles... no
configure: creating ./config.status
config.status: creating Makefile

然后我 运行 制作:

make -j8

这是最后一条错误信息:

make[3]: Entering directory `/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3'
make "AR_FLAGS=rc" "CC_FOR_BUILD=gcc" "CC_FOR_TARGET=/home/hushichen/DensePose-main/gcc-build/./gcc/xgcc -B/home/hushichen/DensePose-main/gcc-build/./gcc/" "CFLAGS=-g -O2" "CXXFLAGS=-g -O2 -D_GNU_SOURCE" "CFLAGS_FOR_BUILD=-g -O2" "CFLAGS_FOR_TARGET=-g -O2" "INSTALL=/usr/bin/install -c" "INSTALL_DATA=/usr/bin/install -c -m 644" "INSTALL_PROGRAM=/usr/bin/install -c" "INSTALL_SCRIPT=/usr/bin/install -c" "LDFLAGS=" "LIBCFLAGS=-g -O2" "LIBCFLAGS_FOR_TARGET=-g -O2" "MAKE=make" "MAKEINFO=/home/hushichen/DensePose-main/gcc-4.9.2/missing makeinfo --split-size=5000000 --split-size=5000000 --split-size=5000000 " "SHELL=/bin/sh" "RUNTESTFLAGS=" "exec_prefix=/usr/local" "infodir=/usr/local/share/info" "libdir=/usr/local/lib" "includedir=/usr/local/include" "prefix=/usr/local" "tooldir=/usr/local/x86_64-unknown-linux-gnu" "gxx_include_dir=/usr/local/include/c++/4.9.2" "AR=ar" "AS=/home/hushichen/DensePose-main/gcc-build/./gcc/as" "LD=/home/hushichen/DensePose-main/gcc-build/./gcc/collect-ld" "RANLIB=ranlib" "NM=/home/hushichen/DensePose-main/gcc-build/./gcc/nm" "NM_FOR_BUILD=" "NM_FOR_TARGET=nm" "DESTDIR=" "WERROR=" all-recursive
make[4]: Entering directory `/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3'
Making all in include
make[5]: Entering directory `/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include'
mkdir -p ./x86_64-unknown-linux-gnu/bits/stdc++.h.gch
mkdir -p ./x86_64-unknown-linux-gnu/bits/stdc++.h.gch
/home/hushichen/DensePose-main/gcc-build/./gcc/xgcc -shared-libgcc -B/home/hushichen/DensePose-main/gcc-build/./gcc -nostdinc++ -L/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/src -L/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs -L/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/libsupc++/.libs -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    -x c++-header -nostdinc++ -g -O2 -D_GNU_SOURCE  -I/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/x86_64-unknown-linux-gnu -I/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include -I/home/hushichen/DensePose-main/gcc-4.9.2/libstdc++-v3/libsupc++ -O2 -g -std=gnu++0x /home/hushichen/DensePose-main/gcc-4.9.2/libstdc++-v3/include/precompiled/stdc++.h \
-o x86_64-unknown-linux-gnu/bits/stdc++.h.gch/O2ggnu++0x.gch
/home/hushichen/DensePose-main/gcc-build/./gcc/xgcc -shared-libgcc -B/home/hushichen/DensePose-main/gcc-build/./gcc -nostdinc++ -L/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/src -L/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs -L/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/libsupc++/.libs -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    -x c++-header -nostdinc++ -g -O2 -D_GNU_SOURCE  -I/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/x86_64-unknown-linux-gnu -I/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include -I/home/hushichen/DensePose-main/gcc-4.9.2/libstdc++-v3/libsupc++ -O2 -g /home/hushichen/DensePose-main/gcc-4.9.2/libstdc++-v3/include/precompiled/stdc++.h -o x86_64-unknown-linux-gnu/bits/stdc++.h.gch/O2g.gch
In file included from /home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/x86_64-unknown-linux-gnu/bits/gthr-default.h:35:0,
                 from /home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/x86_64-unknown-linux-gnu/bits/gthr.h:148,
                 from /home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/ext/atomicity.h:35,
                 from /home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/bits/ios_base.h:39,
                 from /home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/ios:42,
                 from /home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/istream:38,
                 from /home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/sstream:38,
                 from /home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/complex:45,
                 from /home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/ccomplex:38,
                 from /home/hushichen/DensePose-main/gcc-4.9.2/libstdc++-v3/include/precompiled/stdc++.h:52:
/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/ext/concurrence.h:122:34: error: cannot convert ‘<brace-enclosed initializer list>’ to ‘short int’ in initialization
     __gthread_mutex_t _M_mutex = __GTHREAD_MUTEX_INIT;
                                  ^
/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/ext/concurrence.h:177:44: error: cannot convert ‘<brace-enclosed initializer list>’ to ‘short int’ in initialization
     __gthread_recursive_mutex_t _M_mutex = __GTHREAD_RECURSIVE_MUTEX_INIT;
                                            ^
/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/ext/concurrence.h:255:32: error: could not convert ‘0’ from ‘int’ to ‘__pthread_cond_s::<anonymous union>’
     __gthread_cond_t _M_cond = __GTHREAD_COND_INIT;
                                ^
/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/ext/concurrence.h:255:32: error: could not convert ‘0’ from ‘int’ to ‘__pthread_cond_s::<anonymous union>’
/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/ext/concurrence.h:255:32: error: array must be initialized with a brace-enclosed initializer
/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/ext/concurrence.h:255:32: error: array must be initialized with a brace-enclosed initializer
/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/ext/concurrence.h:255:32: error: invalid conversion from ‘void*’ to ‘unsigned int’ [-fpermissive]
/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/ext/concurrence.h:255:32: error: array must be initialized with a brace-enclosed initializer
/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/ext/concurrence.h:255:32: error: too many initializers for ‘__pthread_cond_s’
/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/mutex:63:31: error: cannot convert ‘<brace-enclosed initializer list>’ to ‘short int’ in initialization
     __native_type  _M_mutex = __GTHREAD_MUTEX_INIT;
                               ^
/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/mutex:92:31: error: cannot convert ‘<brace-enclosed initializer list>’ to ‘short int’ in initialization
     __native_type  _M_mutex = __GTHREAD_RECURSIVE_MUTEX_INIT;
                               ^
/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/condition_variable:70:31: error: could not convert ‘0’ from ‘int’ to ‘__pthread_cond_s::<anonymous union>’
     __native_type   _M_cond = __GTHREAD_COND_INIT;
                               ^
/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/condition_variable:70:31: error: could not convert ‘0’ from ‘int’ to ‘__pthread_cond_s::<anonymous union>’
/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/condition_variable:70:31: error: array must be initialized with a brace-enclosed initializer
/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/condition_variable:70:31: error: array must be initialized with a brace-enclosed initializer
/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/condition_variable:70:31: error: invalid conversion from ‘void*’ to ‘unsigned int’ [-fpermissive]
/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/condition_variable:70:31: error: array must be initialized with a brace-enclosed initializer
/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include/condition_variable:70:31: error: too many initializers for ‘__pthread_cond_s’
make[5]: *** [x86_64-unknown-linux-gnu/bits/stdc++.h.gch/O2ggnu++0x.gch] Error 1
make[5]: Leaving directory `/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3/include'
make[4]: *** [all-recursive] Error 1
make[4]: Leaving directory `/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3'
make[3]: *** [all] Error 2
make[3]: Leaving directory `/home/hushichen/DensePose-main/gcc-build/x86_64-unknown-linux-gnu/libstdc++-v3'
make[2]: *** [all-stage1-target-libstdc++-v3] Error 2
make[2]: Leaving directory `/home/hushichen/DensePose-main/gcc-build'
make[1]: *** [stage1-bubble] Error 2
make[1]: Leaving directory `/home/hushichen/DensePose-main/gcc-build'
make: *** [all] Error 2

我没有C++/C编译经验,希望有人能帮助我。 我原来的gcc版本是4.8.5; cmake 版本 3.6.2.

我已经为这个错误搜索了很多。 由于没有人回答,我自己回答,以防其他人有同样的错误。 总之,这是一个与名为 pthread_mutex_t 的变量相关的错误。 此变量的定义和初始化不兼容。

首先,检查 pthread.h 和 pthreadtypes.h

的位置
locate pthread.h
locate pthreadtypes.h

就我而言,我在不同位置有两个 pthread.h 文件。 通常,/usr/include下的是编译过程中使用的文件。 检查 PTHREAD_MUTEX_INITIALIZER 的定义。 它应该是这样的:

{{0, 0, 0, 0, 0, 0, {0, 0}}}

或者用#ifdef定义,但它们几乎是一回事。

然后检查pthreadtypes.h。通常,它低于 /usr/include/位。 找到 pthread_mutex_t 的定义。 一个版本 (ver1.0) 可能如下所示:

typedef union

{

  struct __pthread_mutex_s __data;

  char __size[__SIZEOF_PTHREAD_MUTEX_T];

  long int __align;

} pthread_mutex_t;

另一个版本(ver2.0):

typedef union

{

  struct __pthread_mutex_s

  {

    int __lock;

    unsigned int __count;

    int __owner;

#if __WORDSIZE == 64

    unsigned int __nusers;

#endif

    /* KIND must stay at this position in the structure to maintain

       binary compatibility.  */

    int __kind;

#if __WORDSIZE == 64

    int __spins;

    __pthread_list_t __list;

# define __PTHREAD_MUTEX_HAVE_PREV 1

#else

    unsigned int __nusers;

    __extension__ union

    {

      int __spins;

      __pthread_slist_t __list;

    };

#endif

  } __data;

  char __size[__SIZEOF_PTHREAD_MUTEX_T];

  long int __align;

} pthread_mutex_t;

可以看到第二个要长很多,在union中定义一个带'{}'的struct。所以报错信息一直说cannot convert ‘’ to ‘short int’ in initialization。原因是 PTHREAD_MUTEX_INITIALIZER 在联合中用 {} 初始化了 pthread_mutex_t。 但是,如果您有看起来像 ver1.0 的定义,那么这里就是冲突。那么您可以将定义替换为 ver2.0.

这也可能与您的GNU版本有关。 ver1.0 定义似乎适用于较新的版本。