roxen.lists.pike.general

Subject Author Date
c modules Marcus Agehall (Roxen IS) @ Pi <6341[at]lyskom[dot]lysator[dot]liu[dot]se> 28-08-2009
I'd suggest you take a look at cmods, mostly found in the post_modules
directory. They are written using a sort of "augmented" C that will
ease the burden of implementing C modules for Pike.

To compile such a module, outside of your Pike build tree, you could
use a makefile like:

OBJS=mymodule.o

PIKE?=pike
CFLAGS+=-fPIC -shared `$(PIKE) -x cflags`
LDFLAGS+=-bundle -bind_at_load -flat_namespace -undefined suppress
CC=gcc

all: module.so

module.so: $(OBJS)
	$(LD) $(LDFLAGS) -o $@ $<

mymodule.o: mymodule.c

mymodule.c: mymodule.cmod
	$(PIKE) -x precompile $< > $@


Note that this is taken more or less from one of my projects on a OSX
box. LDFLAGS would need adjustments on other platforms.

It is of course also possible to build pure C modules in a similar
way, but I'd recommend against that. CMOD just makes your life easier.