I'm using Scons 3.0.0 to cross compile for ARM with arm-none-eabi-gcc on Windows with VC++ installed. And scons add /Fo as compile option like this:

arm-none-eabi-gcc /Fobuild\main.o /c source\main.c ...

Here the content of command line:

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
arm-none-eabi-gcc /Fobuild\main.o /c source\main.c -DBOARD_PCA10040 -DBSP_UART_SUPPORT -DCONFIG_GPIO_AS_PINRESET -DFLOAT_ABI_HARD -DNRF52 -DNRF52832_XXAA -DNRF52_PAN_74 -DSWI_DISABLE0 -mcpu=cortex-m4 -mthumb -mabi=aapcs -Wall -Werror -mfloat-abi=hard -mfpu=fpv4-sp-d16 -O3 -g3
arm-none-eabi-gcc: error: /Fobuild\main.o: No such file or directory
arm-none-eabi-gcc: error: /c: No such file or directory
scons: *** [build\main.o] Error 1
scons: building terminated because of errors.

After reading the user guide https://scons.org/doc/production/HTML/scons-user.html and tried as described in this post Using scons to compile C++ code under windows, scons adds "/Fo" as compile option the problem is persisting.

Here is the code of my scons script

import os

cross_compiler = "arm-none-eabi-"

#don't use the default environment
env = Environment(ENV = os.environ)
# env = Environment(**env_options)

env.Replace(AR = cross_compiler + 'ar')
env.Replace(AS = cross_compiler + 'as')
env.Replace(CC    = cross_compiler + "gcc")
env.Replace(CXX   = cross_compiler + "g++")
env.Replace(LD    = cross_compiler + "g++")
env.Replace(LINK  = cross_compiler + 'gcc')
env.Replace(STRIP = cross_compiler + "strip")
env.Replace(RANLIB = cross_compiler + 'ranlib')
env.Replace(OBJCOPY = cross_compiler + 'objcopy')

env.Replace(PROGSUFFIX = ".out")
env.Replace(OBJSUFFIX  = ".o")

env.Replace(TARGET_ARCH = "arm")

env.Replace(LINKFLAGS = [])

env.Replace(TOOLS = [])
# env.Replace(TOOLS = [cross_compiler + 'gcc'])
env.Append(ENV = {'PATH' : os.environ['PATH']})

# Optimization flags
opt_flags = ['-O3', '-g3']
# Uncomment the line below to enable link time optimization
#opt_flags.append('-flto')

# C flags common to all targets
c_flags = [
            '-DBOARD_PCA10040',
            '-DBSP_UART_SUPPORT',
            '-DCONFIG_GPIO_AS_PINRESET',
            '-DFLOAT_ABI_HARD',
            '-DNRF52',
            '-DNRF52832_XXAA',
            '-DNRF52_PAN_74',
            '-DSWI_DISABLE0',
            '-mcpu=cortex-m4',
            '-mthumb',
            '-mabi=aapcs',
            '-Wall',
            '-Werror',
            '-mfloat-abi=hard',
            '-mfpu=fpv4-sp-d16'
           ]

c_flags += opt_flags

env.Replace(CCFLAGS = c_flags)

libs_paths = []

objs = []

libs = []

src_dir = 'source'
build_dir = 'build'

#Set specifics c files
c_files_list=[
                'main'
                ]

obj_extension='.o'


with open('env_dump.txt', 'w') as file:
    env_dumped = env.Dump()
    for key in env_dumped:
        file.write(key)

#Add specifics c and objs
for elt in c_files_list:
   object = build_dir + os.sep + elt + obj_extension
   env.Object(target = object, source = src_dir + os.sep + elt +'.c')
   objs.append(object)

env.Program('Test', objs, LIBS = libs, LIBPATH = libs_paths)

Anyone have an idea ?

Thanks for your help

1 Answers

0
bdbaddog On Best Solutions

You've allowed SCons to load it's default tools into Environment().

This will first try MSVC.. thus the flag you don't want.

See below. I'm only explicitly loading the tools I think you need.

Also simplified the code a bit and forced the DefaultEnvironment to load no tools. This should slightly speed up startup time as it won't try to find and configure MSVC which can be a bit slow.

Try this:

import os
cross_compiler = "arm-none-eabi-"

#don't use the default environment
DefaultEnvironment(tools=[])

# Only specify the tools we're using
env = Environment(ENV = os.environ, tools=['gcc','g++','gnulink','ar'])

# overwrite tool names with our cross compiler tools
for (tool, name) in [
    ('AR','ar'),
    ('AS','as'),
    ('CC','gcc'),
    ('CXX','g++'),
    ('LD','g++'),
    ('LINK','gcc'),
    ('STRIP','strip'),
    ('RANLIB','ranlib'),
    ('OBJCOPY','objcopy')
]:
    env[tool] = cross_compiler + name

env['PROGSUFFIX']  = ".out"
env['OBJSUFFIX']   = ".o"

env['TARGET_ARCH'] = "arm"

env['LINKFLAGS'] = []

env.Append(ENV = {'PATH' : os.environ['PATH']})

# Optimization flags
opt_flags = ['-O3', '-g3']
# Uncomment the line below to enable link time optimization
#opt_flags.append('-flto')

# C flags common to all targets
c_flags = [
            '-DBOARD_PCA10040',
            '-DBSP_UART_SUPPORT',
            '-DCONFIG_GPIO_AS_PINRESET',
            '-DFLOAT_ABI_HARD',
            '-DNRF52',
            '-DNRF52832_XXAA',
            '-DNRF52_PAN_74',
            '-DSWI_DISABLE0',
            '-mcpu=cortex-m4',
            '-mthumb',
            '-mabi=aapcs',
            '-Wall',
            '-Werror',
            '-mfloat-abi=hard',
            '-mfpu=fpv4-sp-d16'
           ]

c_flags += opt_flags

env['CCFLAGS'] = c_flags

libs_paths = []

objs = []

libs = []

src_dir = 'source'
build_dir = 'build'

#Set specifics c files
c_files_list=[
                'main'
                ]

obj_extension='.o'


with open('env_dump.txt', 'w') as file:
    env_dumped = env.Dump()
    for key in env_dumped:
        file.write(key)

#Add specifics c and objs
for elt in c_files_list:
   object = build_dir + os.sep + elt + obj_extension
   env.Object(target = object, source = src_dir + os.sep + elt +'.c')
   objs.append(object)

env.Program('Test', objs, LIBS = libs, LIBPATH = libs_paths)