Verwenden Sie scons mit gcc 4.7 unter CentOS 6

0

Ich folgte den Anweisungen bei So installieren Sie gcc 4.7.x / 4.8.x unter CentOS für die Installation von gcc 4.7.2 unter /opt/centos/devtoolset-1.1/root/. Jetzt möchte ich ein Projekt erstellen, das für die Verwendung von Scons konfiguriert ist. Ich habe folgendes gemacht:

$ 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

und obwohl $CXX erscheint alias 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)

das scons Befehl schlägt fehl, da der Compiler Optionen wie nicht erkennt -0fast und -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"

Der Vollständigkeit halber hier das SConstruct Dateiinhalt (Ich bin kein scons Experte):

# 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')
Daniel
quelle

Antworten:

0

Ich konnte mein eigenes Projekt unter CentOS 6.5 mit devtoolset-1.1 kompilieren und dabei die folgenden Änderungen an meiner SConstruct-Datei vornehmen.

# 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++")

Beachten Sie, dass ich g ++ als Linker-Befehl verwende. Bei Verwendung von "ld" als Linker scheint es, die falschen Standardbibliotheken auszuwählen. Natürlich wird ld irgendwann von g ++ aufgerufen.

Sean McCauliff
quelle