Hi,

   I'm doing some experiments with SWIG (trying to make a Ruby interface for
MuSE low-level sound classes), and I'm having some problems.

   One of them is really weird: it seems that there are problems with extern
"C" declarations (from C++) and with functions _named_ "error" (namely, that
when you try to call the function, the interpreter aborts, without exceptions
or anything).

   Here is my tiny example:

-- errortest.c / errortest.cxx ------ 8< -------------------------------------
#include <stdio.h>

void error(const char *fmt, ...)
{
   printf("I won't be called\n");
}
------------------------------------- >8 -------------------------------------

-- errortest.i ---------------------- 8< -------------------------------------
%module errortest

%{
#include "errortest.h"
%}

#ifdef __cplusplus
extern "C" {
#endif

void error(const char *format, ...);

#ifdef __cplusplus
}
#endif
------------------------------------- >8 -------------------------------------

-- errortest.h ---------------------- 8< -------------------------------------
#ifdef __cplusplus
extern "C" {
#endif

void error(const char *format, ...);

#ifdef __cplusplus
}
#endif
------------------------------------- >8 -------------------------------------

-- Makefile ------------------------- 8< -------------------------------------
BASENAME   = errortest
WRAPPER_BASENAME = $(BASENAME)_wrap
SWIG      = swig
INTERFACE  = $(BASENAME).i
CXXSRCS    = errortest.cpp
SRCDIR     = .
OBJS       = $(CXXSRCS:.cpp=.o)
INCLUDES   = -I.
LINK       = 
CPP        = 1
GCC        = $(if $(CPP),g++,gcc)
SWIG_OPTS  = $(if $(CPP),-c++,)
SRC_EXT = $(if $(CPP),cxx,c)


all: $(BASENAME).so

$(BASENAME).so: $(BASENAME).o $(WRAPPER_BASENAME).o
	$(GCC) -shared $(OBJS) $(WRAPPER_BASENAME).o $(LINK) -o $@

$(BASENAME).o: $(SRCDIR)/$(BASENAME).$(SRC_EXT)
	$(GCC) -fpic -fPIC -DHAVE_CONFIG_H -c -shared $(INCLUDES) $<

$(WRAPPER_BASENAME).o: $(WRAPPER_BASENAME).$(SRC_EXT)
	$(GCC) -fpic -fPIC -DHAVE_CONFIG_H -c -shared $(INCLUDES) -I/usr/lib/ruby/1.8/i386-linux $(WRAPPER_BASENAME).$(SRC_EXT)

$(WRAPPER_BASENAME).$(SRC_EXT): $(INTERFACE)
	$(SWIG) $(SWIG_OPTS) -ruby $(INTERFACE)

clean:
	$(RM) $(BASENAME).so $(BASENAME).o $(WRAPPER_BASENAME).o $(WRAPPER_BASENAME).$(SRC_EXT)

.PHONY: all clean
------------------------------------- >8 -------------------------------------

When I try to use it:

------------------------------------- 8< -------------------------------------
zoso@velutha:~/tmp/swig$ ruby -rerrortest -e "puts Errortest::error('some error')"
ruby:
zoso@velutha:~/tmp/swig$
------------------------------------- >8 -------------------------------------

When I rename the "error" function to "error2", it works great :-?

   Also, if I remove the extern "C" declarations (from both errortest.{h,i}, I
don't know if it makes sense leaving it in errortest.i) but leave the function
as "error", it works, too (note that I tried both with C and C++, hence the
errortest.c{,xx} file and the $(CPP) variable in the Makefile).

   Can anyone shed some light on this?

-- 
Esteban Manchado Vel?zquez <zoso / foton.es> - http://www.foton.es
EuropeSwPatentFree - http://EuropeSwPatentFree.hispalinux.es