开发者

Howto get include directories (ruby.h) for Linux Ruby C extension project?

I'm using scons to build a linux C based ruby extension. What is the "right" way to get the include paths right? By "right" I mean it works out of the box on 1.9 and 1.8.

I don't want to 开发者_如何学JAVAuse the mkmf/Makefile solution.

Thanks! Dave


If you were using autoconf, you could borrow ruby.ac from rice:

http://github.com/jameskilton/rice/blob/master/ruby.ac

or since you are using a different build system, you can duplicate its behavior. To summarize what it does:

  1. We use the rbconfig module to get ruby config variables like this:
    $RUBY -rrbconfig -e "puts(Config::CONFIG['$1'] || '')" <variable>
    where $RUBY is the ruby interpreter (sometimes interpreters get installed with a different name, e.g. ruby1.8 or ruby1.9) and <variable> is the desired config variable
  2. We then set our build variables:
    
      if ${ruby_config_rubyhdrdir} is empty: (e.g. ruby 1.8)
        CPPFLAGS="-I${ruby_config_archdir}
      else:
        CPPFLAGS="-I${ruby_config_rubyhdrdir} ${ruby_config_rubyhdrdir}/${arch}
    
      CFLAGS="${ruby_config_CFLAGS} ${ruby_config_CCDLFLAGS}"
    
      LDFLAGS="-L${ruby_config_archdir} -L${ruby_config_libdir} ${ruby_config_LDFLAGS}"
    
      LIBS="${ruby_config_LIBS} ${ruby_config_DLDLIBS}"
    
    where the variables ${ruby_config_*} are determined using the config command above, e.g.:
    ruby_config_foo=$RUBY -rrbconfig -e "puts(Config::CONFIG['$1'] || '')" foo
  3. We also need to link with the ruby library, so we append ${ruby_config_LIBRUBYARG}.
  4. The above variables are for compiling and linking; you may also need to install. Ruby library files should be installed to ${ruby_config_sitelibdir}. Ruby extensions should be installed to ${ruby_config_sitearchdir}.
  5. There's also some magic in ruby.ac for building with mingw and linking against the one-click installer on windows (which used to be built with vc6; I'm not sure if it still is or not).
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜