我按照以下说明进行操作如何在 CentOS 上安装 gcc 4.7.x/4.8.x用于在 下安装 gcc 4.7.2 /opt/centos/devtoolset-1.1/root/
。现在我想构建一个配置为使用 scons 的项目。我做了以下操作:
$ scl enable devtoolset-1.1 bash
$ export CC=/opt/centos/devtoolset-1.1/root/usr/bin/gcc
$ export CPP=/opt/centos/devtoolset-1.1/root/usr/bin/cpp
$ export CXX=/opt/centos/devtoolset-1.1/root/usr/bin/c++
$ scons --debug=presub
尽管$CXX
看起来是 gcc 4.7.2 的别名:
$ $CXX -v
Using built-in specs.
COLLECT_GCC=/opt/centos/devtoolset-1.1/root/usr/bin/c++
COLLECT_LTO_WRAPPER=/opt/centos/devtoolset-1.1/root/usr/libexec/gcc/x86_64-redhat-linux/4.7.2/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/opt/centos/devtoolset-1.1/root/usr --mandir=/opt/centos/devtoolset-1.1/root/usr/share/man --infodir=/opt/centos/devtoolset-1.1/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --disable-build-with-cxx --disable-build-poststage1-with-cxx --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --enable-languages=c,c++,fortran,lto --enable-plugin --with-linker-hash-style=gnu --enable-initfini-array --disable-libgcj --with-ppl --with-cloog --with-mpc=/home/centos/rpm/BUILD/gcc-4.7.2-20121015/obj-x86_64-redhat-linux/mpc-install --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.7.2 20121015 (Red Hat 4.7.2-5) (GCC)
该scons
命令失败,因为编译器无法识别诸如-0fast
和之类的选项-std=c++1y
:
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
Building build/gcc/optimized/ai.o with action:
$CXX -o $TARGET -c $CXXFLAGS $CCFLAGS $_CCCOMCOM $SOURCES
Compiling build/gcc/optimized/ai.o
cc1plus: error: invalid option argument '-Ofast'
cc1plus: error: unrecognized command line option "-Wdouble-promotion"
cc1plus: error: unrecognized command line option "-Wnoexcept"
cc1plus: error: unrecognized command line option "-Wtrampolines"
cc1plus: error: unrecognized command line option "-Wvector-operation-performance"
cc1plus: error: unrecognized command line option "-std=c++1y"
cc1plus: error: unrecognized command line option "-fnothrow-opt"
cc1plus: error: unrecognized command line option "-flto=4"
cc1plus: warnings being treated as errors
cc1plus: error: unrecognized command line option "-Wno-maybe-uninitialized"
为了完整起见,这里是SConstruct
文件内容(我不是scons
专家):
# SCons file
# Copyright (C) 2013 David Stone
#
# This program is free software: you can redistribute it and / or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import multiprocessing
from build_scripts.sources import base_sources
SetOption('warn', 'no-duplicate-environment')
# Options to improve the default speed of SCons
SetOption('max_drift', 2)
SetOption('implicit_cache', 1)
SetOption('num_jobs', multiprocessing.cpu_count())
AddOption('--compiler', dest = 'compiler', type = 'string', action = 'store', help = 'Name of the compiler to use.')
AddOption('--compiler-command', dest = 'compiler_command', type = 'string', action = 'store', help = 'Command to launch the compiler.')
AddOption('--verbose', dest = 'verbose', action = "store_true", help = 'Print the full compiler output.')
Decider('MD5-timestamp')
SConscript('build_scripts/compiler_settings.py')
Import('flags', 'compiler_command', 'compiler_name')
default = DefaultEnvironment()
default.Append(CPPPATH= ['endian', 'bounded_integer'])
# This replaces the wall of text caused by compiling with max warnings turned on
# into something a little more readable.
if not GetOption('verbose'):
default['CXXCOMSTR'] = 'Compiling $TARGET'
default['LINKCOMSTR'] = 'Linking $TARGET'
default.Replace(CXX = compiler_command)
def setup_environment_flags(version):
environment = default.Clone()
environment.Append(CCFLAGS = flags['cc'][version])
environment.Append(CXXFLAGS = flags['cxx'][version])
environment.Append(LINKFLAGS = flags['link'][version])
environment.Append(CPPDEFINES = flags['cpp'][version])
if version != 'default':
build_root = 'build/' + compiler_name + '/'
environment.VariantDir(build_root + version, 'source', duplicate = 0)
return environment
default = setup_environment_flags('default')
debug = setup_environment_flags('debug')
optimized = setup_environment_flags('optimized')
def generate_sources(sources, version, compiler_name):
temp = []
for source in sources:
temp += ['build/' + compiler_name + '/' + version + '/' + source]
return temp
def create_program(base):
env = { 'debug':debug, 'optimized':optimized }
suffix = { 'debug':'-debug', 'optimized':'' }
name, sources, libraries = base
for version in ['debug', 'optimized']:
targets = generate_sources(sources, version, compiler_name)
executable_name = name + suffix[version]
env[version].Clone(LIBS = libraries).Program(executable_name, targets)
for sources in base_sources:
create_program(sources)
SConscript('build_scripts/settings_file.py')
答案1
我能够使用 devtoolset-1.1 在 CentOS 6.5 上编译我自己的项目,并对我的 SConstruct 文件进行以下修改。
# Top level Scons environment.
env = Environment()
env.Replace(CXX = "/opt/centos/devtoolset-1.1/root/usr/bin/gcc")
env.Replace(CC = "/opt/centos/devtoolset-1.1/root/usr/lib/gcc/x86_64-redhat-linux/4.7.2/cc")
env.Replace(CPP = "/opt/centos/devtoolset-1.1/root/usr/lib/gcc/x86_64-redhat-linux/4.7.2/cpp")
env.Replace(LINK = "/opt/centos/devtoolset-1.1/root/usr/bin/g++")
请注意,我使用 g++ 作为链接器命令。使用“ld”作为链接器时,似乎选择了错误的标准库。当然,ld 最终由 g++ 调用。