Difficulty with name-mangling when extending Ruby with Thrust (C++)

Hello,

I’m trying to extend Ruby with Thrust for a short physics project of
mine, but I keep running into some trouble with C++'s name mangling.
Specifically, when calling functions such as thrust::replace or
thrust::sequence, I get errors similar to the following:

irb: symbol lookup error: /home/ralfgunter/ruby/thrust/thrust.so:
undefined symbol:
ZN6thrust6detail6device4cuda9vectorizeIiNS1_6detail26unary_transform_if_functorINS_10device_ptrIfEES7_S7_NS0_14constant_unaryIfEENS0_20if_equal_to_exemplarIfEEEEEEvT_T0

This is not always the case - thrust::fill works fine, for instance. I
am using nvcc from CUDA 2.3, Ruby 1.9.1-p243, gcc 4.3.3 (ubuntu), and I
had to mess a bit with the Makefile to compile; these were the
workarounds:

  1. Replaced ‘g++’ with ‘nvcc’
  2. Replaced every instance of ‘-Wl,’ with '-Xlinker ’
  3. Added a '-Xcompiler ’ before ‘-Wall’, ‘-rdynamic’, and pretty much
    everything else that would make ‘make’ spit out an error.

As far as I know, this is usually solved by wrapping the ‘offending
functions’ with ‘extern “C”’, though now the functions I’m having some
difficulty with are Thrust’s own, so I think this solution might not
apply in this case. Please do correct me if I’m wrong!

I’d love if anyone could help me with this one, as it’s been bugging me
for a while!

Cheers,
Ralf