You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apreq-dev@httpd.apache.org by Alexander Farber <al...@gmail.com> on 2006/01/31 00:06:30 UTC

How to link my C module against libapreq.a?

Hi,

could someone please give me a hint,
how to use libapreq from my Apache module?

I'm using Apache 1.3.29 on OpenBSD 3.9-beta,
with the p5-libapreq-1.3 package which includes these files:

/usr/local/libdata/perl5/site_perl/i386-openbsd/auto/libapreq/include/apache_cookie.h
/usr/local/libdata/perl5/site_perl/i386-openbsd/auto/libapreq/include/apache_multipart_buffer.h
/usr/local/libdata/perl5/site_perl/i386-openbsd/auto/libapreq/include/apache_request.h
/usr/local/libdata/perl5/site_perl/i386-openbsd/auto/libapreq/libapreq.a

My module contains 3 files (mod_pref.c, mod_pref.h and pgsql.c
in the subdir module/) and builds and works fine using these commands:

gcc -Wall -ggdb -O0 -O2 -pipe -DDEV_RANDOM=/dev/arandom
-DMOD_SSL=208116 -DEAPI -DUSE_SETUSERCONTEXT -fPIC -DSHARED_MODULE -I
/usr/lib/apache/include  -I /usr/local/include/postgresql -c
module/mod_pref.c -o build/mod_pref.o

gcc -Wall -ggdb -O0 -O2 -pipe -DDEV_RANDOM=/dev/arandom
-DMOD_SSL=208116 -DEAPI -DUSE_SETUSERCONTEXT -fPIC -DSHARED_MODULE -I
/usr/lib/apache/include  -I /usr/local/include/postgresql -c
module/pgsql.c -o build/pgsql.o

gcc -shared -fPIC -DSHARED_MODULE -L /usr/local/lib -lpq
build/mod_pref.o build/pgsql.o -o mod_pref.so

apxs -n pref -a -i mod_pref.so

When I add however these 3 lines to my mod_pref.c:

        #include <apache_request.h>
 ....
        ApacheRequest *req = ApacheRequest_new(r);
        req->disable_uploads = 1;

And to the compile and linking commands above - corresponding:

        -I /usr/local/libdata/perl5/site_perl/i386-openbsd/auto/libapreq/include
and
         -L /usr/local/libdata/perl5/site_perl/i386-openbsd/auto/libapreq
-lapreq  \
        /usr/local/libdata/perl5/site_perl/i386-openbsd/auto/libapreq/libapreq.a

then the mod_pref.so does build, but I can't run the httpd anymore:

    laptop:afarber {862} sudo /usr/sbin/httpd -X
    /usr/sbin/httpd:/usr/lib/apache/modules/mod_pref.so: undefined
symbol 'ApacheRequest_new'

I'm thankful for any hints as I couldn't find the solution on the web yet
nor in the WRAPMOD book I own

Is maybe the OpenBSD package wrong and a shared library is missing?

Or do I maybe need to rebuild the httpd itself and link it against libapreq.a?

Regards
Alex

PS: Here some more info from my PC:

    laptop:afarber {532} perl -MApache::libapreq -e ccopts
    -I/usr/local/libdata/perl5/site_perl/i386-openbsd/auto/libapreq/include

    laptop:afarber {533} perl -MApache::libapreq -e ldopts
    -L/usr/local/libdata/perl5/site_perl/i386-openbsd/auto/libapreq -lapreq

PPS: And here is my Makefile (I don't use "apxs -c", because I want .o files
        go into "build/" subdir and the target mod_pref.so into the top dir)

# PostgreSQL flags
PG_CFLAGS  := -I $(shell pg_config --includedir)
PG_LDFLAGS := -L $(shell pg_config --libdir) -lpq

# Apache module flags
LIBAPREQ    = /usr/local/libdata/perl5/site_perl/i386-openbsd/auto/libapreq
AP_CFLAGS  := $(shell apxs -q CFLAGS) $(shell apxs -q CFLAGS_SHLIB) \
                -I $(shell apxs -q INCLUDEDIR) -I $(LIBAPREQ)/include
AP_LDFLAGS := $(shell apxs -q LDFLAGS_SHLIB) \
                -L $(LIBAPREQ) -lapreq $(LIBAPREQ)/libapreq.a

VPATH   = media server module java-client
MODULE  = mod_pref.c pgsql.c
MODOBJS = $(MODULE:%.c=$(BUILD)/%.o)

mod_pref.so: $(MODOBJS)
        $(CC) $(AP_LDFLAGS) $(PG_LDFLAGS) $^ -o $@

$(MODOBJS): $(BUILD)/%.o: %.c mod_pref.h
        $(CC) $(CFLAGS) $(AP_CFLAGS) $(PG_CFLAGS) -c $< -o $@

Re: How to link my C module against libapreq.a?

Posted by Alexander Farber <al...@gmail.com>.
Nevermind, I've figured it out by rereading "man gcc"!
I have to put my .o files before the -L ... -lapreq:

gcc build/mod_pref.o build/pgsql.o -shared -fPIC -DSHARED_MODULE -L
/usr/local/libdata/perl5/site_perl/i386-openbsd/auto/libapreq -lapreq
-L /usr/local/lib -lpq -o mod_pref.so

On 1/31/06, Alexander Farber <al...@gmail.com> wrote:
> could someone please give me a hint,
> how to use libapreq from my Apache module?
...
>     laptop:afarber {862} sudo /usr/sbin/httpd -X
>     /usr/sbin/httpd:/usr/lib/apache/modules/mod_pref.so: undefined
> symbol 'ApacheRequest_new'