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:
- We use the rbconfig module to get ruby config variables like this:
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$RUBY -rrbconfig -e "puts(Config::CONFIG['$1'] || '')" <variable>
- We then set our build variables:
where the variables ${ruby_config_*} are determined using the config command above, e.g.: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}"
ruby_config_foo=$RUBY -rrbconfig -e "puts(Config::CONFIG['$1'] || '')" foo
- We also need to link with the ruby library, so we append ${ruby_config_LIBRUBYARG}.
- 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}.
- 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).
精彩评论