Name clash in C extension

A

Alex Gutteridge

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 Gutteridge

Bioinformatics Center
Kyoto University
 
A

Alex Gutteridge

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).

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 Gutteridge

Bioinformatics Center
Kyoto University
 
G

Gabor Csardi

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top