0

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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Phong
  • 6,600
  • 4
  • 32
  • 61

1 Answers1

3

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)
Phong
  • 6,600
  • 4
  • 32
  • 61
  • I was just about to post the same thing. +1 Note: if you just want to set the environment variable you could do env = Environment(ENV = {'DISPLAY' : '0' }) – gnash117 Dec 15 '12 at 07:38
  • I have notice a problem with the above code. It fail if the DISPLAY environement is not set (better check if it is set before getting the value) – Phong Dec 23 '12 at 03:14