Please note:The SCons wiki is now restored from the attack in March 2013. All old passwords have been invalidated. Please reset your password if you have an account. If you note missing pages, please report them to webmaster@scons.org. Also, new account creation is currently disabled due to an ongoing spam flood (2013/08/27).

The simplest way is to do something like this:

   1 # use GTK
   2 CCFLAGS = ' `pkg-config --cflags gtk+-2.0` '
   3 LINKFLAGS = ' `pkg-config --libs gtk+-2.0` '
   4 
   5 env = Environment(CCFLAGS=CCFLAGS, LINKFLAGS=LINKFLAGS)
   6 env.Program('toaster-test.c')

Remember to keep them separate, you cannot do what you do in makefiles and specify --cflags and --libs together.

However, the cleaner, more correct - and really not much harder - way is to use ParseConfig like so:

   1 env = Environment()
   2 
   3 # add support for GTK
   4 env.ParseConfig('pkg-config --cflags --libs gtk+-2.0')
   5 
   6 env.Program('toaster-test.c')

Of course, the above steps assume pkg-config and GTK+ are installed (though they will almost always be). If you want your configuration to be able to check for the existence of pkg-config, use something like what follows:

   1 env = Environment()
   2 
   3 def CheckPKGConfig(context, version):
   4      context.Message( 'Checking for pkg-config... ' )
   5      ret = context.TryAction('pkg-config --atleast-pkgconfig-version=%s' % version)[0]
   6      context.Result( ret )
   7      return ret
   8 
   9 def CheckPKG(context, name):
  10      context.Message( 'Checking for %s... ' % name )
  11      ret = context.TryAction('pkg-config --exists \'%s\'' % name)[0]
  12      context.Result( ret )
  13      return ret
  14 
  15 # Configuration:
  16 
  17 conf = Configure(env, custom_tests = { 'CheckPKGConfig' : CheckPKGConfig,
  18                                        'CheckPKG' : CheckPKG })
  19 
  20 if not conf.CheckPKGConfig('0.15.0'):
  21      print 'pkg-config >= 0.15.0 not found.'
  22      Exit(1)
  23 
  24 if not conf.CheckPKG('gtk+-2.0 >= 2.4.9'):
  25      print 'GTK+-2.0 >= 2.4.9 not found.'
  26      Exit(1)
  27 
  28 # Your extra checks here
  29 
  30 env = conf.Finish()
  31 
  32 # Now, build:
  33 
  34 env.ParseConfig('pkg-config --cflags --libs gtk+-2.0')
  35 
  36 env.Program('toaster-test.c')

UsingPkgConfig (last edited 2013-04-03 15:04:16 by JoelAlmeida)