Name clash in C extension

Hi,

I’m trying to write an extension interfacing with the C iGraph
library (http://cneurocvs.rmki.kfki.hu/igraph/). Unfortunately the
iGraph header files define a macro called TYPE which clashes with the
TYPE macro defined in ruby.h. Both headers are obviously required to
compile my extension.

What is the best practice for dealing with name clashes like this? My
current solution is to do a search and replace in the iGraph source
changing TYPE to IGRAPH_TYPE and recompile the library. That works
for now, but implies anyone else wanting to build my extension will
have to manually hack iGraph themselves which seems a bit off. Am I
missing some obvious solution other than emailing iGraph/Ruby core
and asking for them to play a bit nicer with their names?

Alex G.

Bioinformatics Center
Kyoto University

On 6/25/07, Alex G. [email protected] wrote:

Hi,

I’m trying to write an extension interfacing with the C iGraph
library (http://cneurocvs.rmki.kfki.hu/igraph/). Unfortunately the
iGraph header files define a macro called TYPE which clashes with the
TYPE macro defined in ruby.h. Both headers are obviously required to
compile my extension.

What happens if you define a wrapper for the calls you make to the
IGraph
liibrary? That way you include only the wrapper’s header in the
extension’s
main source file (the one that includes ruby.h and defines Init_xxx).
You’ll
have to massage all data items between Ruby-land and C in the wrapper as
well. I took this approach in the EventMachine library (where it has an
additional benefit because the wrapper is in C, but the extension code
is
all in C++, so the wrapper approach avoids exposing decorated symbols in
the
compiled extension).

On 25 Jun 2007, at 20:04, Francis C. wrote:

What happens if you define a wrapper for the calls you make to the
code is
all in C++, so the wrapper approach avoids exposing decorated
symbols in the
compiled extension).

Thanks for the pointer. I’d been trying to shortcut and use SWIG to
generate the extension, but it looks like I will have to abandon that
for the time being anyway (too complicated, makes my head hurt). I
will have a look at EventMachine and see if I can use the same
wrapper technique here.

Alex G.

Bioinformatics Center
Kyoto University

Alex, i’m an igraph developer, and there is an easy solution for this i
think,
all you need is to append

#ifdef TYPE
#undef TYPE
#endif

#ifdef FUNCTION
#undef FUNCTION
#endif

to the file igraph_pmt_off.h. (This was an igraph bug, not having these
there.) Please feel free to contact me if you need any help.

Best,
Gabor

Alex G. wrote:

Hi,

I’m trying to write an extension interfacing with the C iGraph
library (http://cneurocvs.rmki.kfki.hu/igraph/). Unfortunately the
iGraph header files define a macro called TYPE which clashes with the
TYPE macro defined in ruby.h. Both headers are obviously required to
compile my extension.

What is the best practice for dealing with name clashes like this? My
current solution is to do a search and replace in the iGraph source
changing TYPE to IGRAPH_TYPE and recompile the library. That works
for now, but implies anyone else wanting to build my extension will
have to manually hack iGraph themselves which seems a bit off. Am I
missing some obvious solution other than emailing iGraph/Ruby core
and asking for them to play a bit nicer with their names?

Alex G.

Bioinformatics Center
Kyoto University

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs