On Tue, Jan 13, 2009 at 22:20, wolfgang <wolfgang...@gmail.com> wrote: > Hi, Sorin > > Thanks for quick reply. > > Here are mod_test.c and Makefile > > ********************** mod_test.c **************************************** > #include "httpd.h" > #include "http_config.h" > #include "http_protocol.h" > #include "ap_config.h" > > #include "my_test.h" > > /* The sample content handler */ > static int test_handler(request_rec *r) > { > if (strcmp(r->handler, "test")) { > return DECLINED; > } > r->content_type = "text/html"; > > printf("test_handler is called\n"); > > if (!r->header_only){ > ap_rputs("The sample page from mod_test.c\n", r); > printf("%d\n", add_test(10,20)); // <--- HERE !!! > } > > return OK; > } > > static void test_register_hooks(apr_pool_t *p) > { > ap_hook_handler(test_handler, NULL, NULL, APR_HOOK_MIDDLE); > } > > /* Dispatch list for API hooks */ > module AP_MODULE_DECLARE_DATA test_module = { > STANDARD20_MODULE_STUFF, > NULL, /* create per-dir config structures */ > NULL, /* merge per-dir config structures */ > NULL, /* create per-server config structures */ > NULL, /* merge per-server config structures */ > NULL, /* table of config file commands */ > test_register_hooks /* register hooks */ > }; > ------------------------------------------------------------------------------------------- > > ********************** Makefile **************************************** > ## > ## Makefile -- Build procedure for sample test Apache module > ## Autogenerated via ``apxs -n test -g''. > ## > > builddir=. > top_srcdir=/usr/local/apache > top_builddir=/usr/local/apache > include /usr/local/apache/build/special.mk > > # the used tools > APXS=apxs > APACHECTL=apachectl > > # additional defines, includes and libraries > #DEFS=-Dmy_define=my_value > #INCLUDES=-Imy/include/dir > #LIBS=-Lmy/lib/dir -lmylib > > # the default target > all: local-shared-build > > # install the shared object file into Apache > install: install-modules-yes > > # cleanup > clean: > -rm -f mod_test.o mod_test.lo mod_test.slo mod_test.la > > # simple test > test: reload > lynx -mime_header http://localhost/test > > # install and activate shared object by reloading Apache to > # force a reload of the shared object file > reload: install restart > > # the general Apache start/restart/stop > # procedures > start: > $(APACHECTL) start > restart: > $(APACHECTL) restart > stop: > $(APACHECTL) stop > ---------------------------------------------------------------------------------- > > And I have one more file, modules.mk. it was created when I did > "/usr/local/apache/bin/apxs -g -n test". > I have no idea what it is. ( I didn't modify this file at all )
Assuming that your extra source file is called my_extra_source_file.c, add my_extra_source_file.slo and my_extra_source_file.lo to modules.mk as shown below. > *************************** modules.mk *********************** > mod_test.la: mod_test.slo my_extra_source_file.slo > $(SH_LINK) -rpath $(libexecdir) -module -avoid-version mod_test.lo > my_extra_source_file.lo > DISTCLEAN_TARGETS = modules.mk > shared = mod_test.la > ----------------------------------------------------------------------------------- > > I built the module as follows > $ make > and to install > $ make install > > I know I should do something at the "all" target like making > my_test.c's object file and link it to mod_test but don't know how to > specify at all... > > Thanks in advance. > > wolfgang > > > > > On Wed, Jan 14, 2009 at 6:04 AM, Sorin Manolache <sor...@gmail.com> wrote: >> On Tue, Jan 13, 2009 at 21:48, wolfgang <wolfgang...@gmail.com> wrote: >>> Hi gurus, >>> >>> I made a sample apache module, mod_test, by >>> "/usr/local/apache/bin/apxs -g -n test". >>> Now I want to make the mod_test call the following source ( actually, >>> an add_test function ). >>> >>> ----------- my_test.h ------------ >>> #ifndef _MY_TEST_H >>> #define _MY_TEST_H 1 >>> >>> int add_test(int a, int b); >>> >>> #endif >>> ---------------------------------------- >>> >>> ------------ my_test.c ----------- >>> #include "my_test.h" >>> >>> int add_test(int a, int b){ >>> return (a+b); >>> } >>> ---------------------------------------- >>> >>> I've added #include "my_test.h" in mod_test.c and also add_test(10,20) >>> in the test_handler function as follows. >>> >>> /* The sample content handler */ >>> static int test_handler(request_rec *r) >>> { >>> if (strcmp(r->handler, "test")) { >>> return DECLINED; >>> } >>> r->content_type = "text/html"; >>> >>> printf("test_handler is called\n"); >>> >>> if (!r->header_only){ >>> ap_rputs("The sample page from mod_test.c\n", r); >>> printf("%d\n", add_test(10,20)); // <--- HERE !!! >>> } >>> return OK; >>> } >>> >>> and compiled and installed as follows >>> ( I've added LoadModule, SetHandler in httpd.conf ) >>> >>> $ make >>> $ make install >>> >>> run apache as debug mode >>> $ /usr/local/apache/bin/httpd -X >>> >>> Then, I get the following error. >>> >>> httpd: Syntax error on line 100 of /usr/local/apache/conf/httpd.conf: >>> Cannot load /usr/local/apache/modules/mod_test.so into server: >>> /usr/local/apache/modules/mod_test.so: undefined symbol: add_test >>> >>> Of course, I get the error since I haven't modified Makefile at all. >>> >>> Now, my question is how Makefile should be modified ??? >>> >>> ------------------------------------- >>> # the used tools >>> APXS=apxs >>> APACHECTL=apachectl >>> >>> # additional defines, includes and libraries >>> #DEFS=-Dmy_define=my_value >>> #INCLUDES=-Imy/include/dir >>> #LIBS=-Lmy/lib/dir -lmylib >>> >>> # the default target >>> all: local-shared-build >>> >>> # install the shared object file into Apache >>> install: install-modules-yes >>> >>> # cleanup >>> clean: >>> -rm -f mod_test.o mod_test.lo mod_test.slo mod_test.la >>> ------------------------------------- >> >> Please attach your whole Makefile. >> >> Please indicate the list of source files. As far as I understood, you >> have mod_test.h and mod_test.c that contain the declaration and >> definition of add_test. Which file contains test_handler and the >> test_module structure? >> >> -- >> S >> >>> >>> I'm stuck over 8 hours... I couldn't find any sites describing this >>> kinda situation. >>> I'm really new to Makefile but no time to learn Makefile from a >>> scratch right now.... :( >>> Please please please help me out... >>> >>> thanks in advance. >>> >>> wolfgang >>> >> >> >> >> -- >> A: Because it reverses the logical flow of conversation. >> Q: Why is top-posting frowned upon? >> A: Top-posting. >> Q: What is the most annoying thing in e-mail? >> > -- A: Because it reverses the logical flow of conversation. Q: Why is top-posting frowned upon? A: Top-posting. Q: What is the most annoying thing in e-mail?