Mind Ramblings My Blog

Building the wrappers

This week was very engaging and a little hectic at the end for me. I had to rethink many things during the week, like these wrappers. I had to rewrite them, because of a logical error in the allocation of the pointers that pointed to the data. And spent a whole lot of time trying to understand a hack of passing a variable by reference in c only to conclude that it can’t be used! Anyways, I learnt a new c hack! You can refer to this question that I asked on stack overflow.

So, the wrappers for Basic were written. But they didn’t compile because of a missing -fPIC flag that evidently cmake puts it on its own and rake doesn’t. The flag, I guess, was required to enable building of shared libs. The error message was something like this

After hours and hours of googling and reading code on github, I figured out a way to add it. It needs to be added to the variable $CFLAGS which is in extconf.rb.

#File: extconf.rb
$CFLAGS << ' -Wall' unless $CFLAGS.split.include?('-Wall')
$CFLAGS << ' -Werror' unless $CFLAGS.split.include?('-Werror')
$CFLAGS << ' -fPIC' unless $CFLAGS.split.include?('-fpic')

And again there was another error
Which was basically because of the static qualifier. Apparently it was local only to that file. Removing the static qualifier got rid of the errors. Thanks to Ondrej, who was there to help with any problem I faced during the whole week.

And finally… the extension built.

I built the gem and installed it. But I am not yet able to load the extension. There might be some issue with the library path. I will fix that and update it. That will be fixed hopefully in a day or two. And then I will build on the minimal test that I wrote.

The next week I will be a little busy with the competition but I can at least fix the errors in loading the extension properly in irb and add the remaning methods. The plan now for the next coding week is to add wrappers for the Symbol class and Integer.

1. Rewrote Ruby C wrappers w/o typedefed array basic
2. Added bare test file for Basic class
3. Fixed an error in Gemfile and added README
4. Added WITH_RUBY flags to CMakeLists.txt
5. Added flag -fPIC. Still doesn’t compile
6. Changes to build the ruby extensions
7. Change in require_path of gemspec
8. Removed the static qualifier in wrappers

comments powered by Disqus