Search code examples
environment-variablesscons

How to define environment variable when running a compiled program with scons


I did write my SConstruct file so I build and run the program by doing scons run

program = env.Program('build/output', Glob('build/test/*.cpp'))
env.Default(program)
env.Alias('run', program, program[0].abspath)

I can compile my program and run it without problem, but when I try to use glut and opengl in my program, I have the following error:

/home/tran/workspace/bobail/build/test/test
freeglut (/home/tran/workspace/bobail/build/test/test): failed to open display ''

After some search I found out that my compiled program need the environment variable DISPLAY to be set to DISPLAY=:0. I tried using Scons Export command but with no success so far.

Could somebody tell me how to do it.

EDIT: My program work fine if I execute it from command line instead of Scons environment.


Solution

  • I found out how to do it. You need to retrieve the DISPLAY global environment and import it in scons environment. This you use this environment to define the alias for running the program.

    test_env = Environment()
    test_env.Append(ENV = {'DISPLAY' : os.environ['DISPLAY']})
    test = test_env.Program(build_path + '/test/test', Glob(build_path + '/test/*.cpp'))
    test_env.Alias('check', test, test[0].abspath)