radix
radix

Reputation: 394

How to use scons for cross build

I am trying to create the simplest imaginable SConstruct file for cross compiling a program. I tried different settings, the latest SConstruct file is here:

env_options = {
    "CC"    : "arm-linux-gnueabihf-gcc",
    "CXX"   : "arm-linux-gnueabihf-g++",
    "LD"    : "arm-linux-gnueabihf-ld",
    "AR"    : "arm-linux-gnueabihf-ar",
    "STRIP" : "arm-linux-gnueabihf-strip"
}
env = Environment(**env_options)
path = ['/path/to/toolchain/bin/']
env.Append( ENV = {'PATH' : path})

p = Program( "prog", [ "prog.c", "mylib.c" ], CFLAGS=[ '-Iinclude', '-Werror', '-Wall', '-Wextra' ] )

The output of env.Dump() shows e.g.:

{ 'AR': 'arm-linux-gnueabihf-ar',
  'CC': 'arm-linux-gnueabihf-gcc',
  'CXX': 'arm-linux-gnueabihf-g++',
  'ENV': { 'PATH': [ '/path/to/toolchain/bin/']},
  'LD': 'arm-linux-gnueabihf-ld',
  'TOOLS': [ 'default',
         'gnulink',
         'gcc',
         'g++',
         'gas',
         'ar',
         'filesystem',
         'm4',
         'zip']
}

I don't see any surprises in the env.Dump() output (especially no standard system paths), and thought that in case scons can not find the tools listed in env_options I would at least get an error message. Instead, scons uses the default tools and builds the program for my host system. I've considered the answers posted here(1) and here(2) - with no success so far.

Upvotes: 4

Views: 1378

Answers (1)

bdbaddog
bdbaddog

Reputation: 3509

p = Program( "prog", [ "prog.c", "mylib.c" ], CFLAGS=[ '-Iinclude', '-Werror', '-Wall', '-Wextra' ] )

Should be

p = env.Program( "prog", [ "prog.c", "mylib.c" ], CFLAGS=[ '-Iinclude', '-Werror', '-Wall', '-Wextra' ] )

Using Program instead of env.Program uses the default environment which doesn't have CC,etc set to any non-default values.

Upvotes: 2

Related Questions