Linking one Ruby extension to another Ruby extension with mkmf
|ruby -v:||ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux]||Backport:||1.9.3: UNKNOWN, 2.0.0: UNKNOWN|
The problem lies within 'mkmf' of ruby.
If we have a gem which contains a native extension consisting of two libraries called 'libfail' and 'good' in C/C++ and both of these libraries have Ruby extensions it is not possible to compile and link them against each other without patching 'mkmf.rb'.
A sample git-repository is here: https://github.com/FlavourSys/ruby-native-extension-bug
If we call 'rake compile' it terminates with an error, because 'find_library' of 'mkmf' is not able to link against 'libfail'. The problem is that the 'ruby-static' libraries are added as g++ option before 'libfail' is.
A simple monkey patch is provided in the git repository. The solution is to just change the order of arguments for the compiler.