2016-02-20 1 views
1

Я пытаюсь написать модуль hello world для Apache HTTPD 2.4. При создании модуля я получаю некоторые ошибки компоновщика, и многие поисковые запросы Google не обнаружили решения.Ошибки компоновщика в базовом модуле Apache

Мои вопросы:

  1. Как я могу исправить ошибку ap_hook_handler компоновщика? Я искал источник и заголовки Apache Portable Runtime и не нашел его.
  2. Почему существует неопределенная ссылка на главную? Я думал, что общие объекты не имеют главной() точки входа.

Исходный код:

// Dependancies: apr-devel apr-util-devel 

#include <httpd.h> 
#include <http_config.h> 
#include <apr_hooks.h> 

static int test_handler(request_rec* request) 
{ 
     return OK; 
} 

static void register_hooks(apr_pool_t *pool) 
{ 
     ap_hook_handler(test_handler, NULL, NULL, APR_HOOK_LAST); 
} 

module AP_MODULE_DECLARE_DATA test_module = 
{ 
     STANDARD20_MODULE_STUFF, 
     NULL, 
     NULL, 
     NULL, 
     NULL, 
     NULL, 
     register_hooks 
}; 

Команда сборки:

apxs -lapr-1 -laprutil-1 -c test.c -o mod_test.so 

Ошибки:

apxs -lapr-1 -laprutil-1 -c test.c -o mod_test.so 
/usr/lib64/apr-1/build/libtool --silent --mode=compile gcc -prefer-pic -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wformat-security -fno-strict-aliasing -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -pthread -I/usr/include/httpd -I/usr/include/apr-1 -I/usr/include/apr-1 -c -o test.lo test.c && touch test.slo 
/usr/lib64/apr-1/build/libtool --silent --mode=link gcc -o test.la -lapr-1 -laprutil-1 -rpath /usr/lib64/httpd/modules -module -avoid-version test.lo -o mod_test.so 
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o: In function `_start': 
(.text+0x20): undefined reference to `main' 
.libs/test.o: In function `register_hooks': 
/root/test/test.c:14: undefined reference to `ap_hook_handler' 
collect2: ld returned 1 exit status 
apxs:Error: Command failed with rc=65536 
+0

Я не знаю 'apxs', но при использовании' gcc' нужно предоставить параметр '-shared' для создания общей библиотеки. Этот параметр не указан в выводе отладки. –

ответ

2

Вопросы, порядок и имена файлов должны идти последним:

apxs -c -o mod_test.so test.c 

Чтобы установить его автоматически:

apxs -i -c -o mod_test.so -c test.c 

Это должно работать

1

Как сказал Ctx, порядок параметров действительно имеет значение. Я использую следующий формат APXS:

$APACHE/bin/apxs -c -a -i mod_test.c 

Что собирает, добавляет и устанавливает тестовый модуль. Она производит этот выход:

/usr/local/apr/build-1/libtool --silent --mode=compile gcc -prefer-pic -DLINUX -D_REENTRANT -D_GNU_SOURCE -g -O2 -pthread -I$APACHE_HOME/include -I/usr/local/apr/include/apr-1 -I/usr/local/apr/include/apr-1 -c -o mod_test.lo mod_test.c && touch mod_test.slo 
/usr/local/apr/build-1/libtool --silent --mode=link gcc -o mod_test.la -rpath $APACHE_HOME/modules -module -avoid-version mod_test.lo 
ar: `u' modifier ignored since `D' is the default (see `U') 
$APACHE_HOME/build/instdso.sh SH_LIBTOOL='/usr/local/apr/build-1/libtool' mod_test.la $APACHE_HOME/modules 
/usr/local/apr/build-1/libtool --mode=install install mod_test.la $APACHE_HOME/modules/ 
libtool: install: install .libs/mod_test.so $APACHE_HOME/modules/mod_test.so 
libtool: install: install .libs/mod_test.lai $APACHE_HOME/modules/mod_test.la 
libtool: install: install .libs/mod_test.a $APACHE_HOME/modules/mod_test.a 
libtool: install: chmod 644 $APACHE_HOME/modules/mod_test.a 
libtool: install: ranlib $APACHE_HOME/modules/mod_test.a 
libtool: finish: 
---------------------------------------------------------------------- 
Libraries have been installed in: 
    $APACHE_HOME/modules 

If you ever happen to want to link against installed libraries 
in a given directory, LIBDIR, you must either use libtool, and 
specify the full pathname of the library, or use the `-LLIBDIR' 
flag during linking and do at least one of the following: 
    - add LIBDIR to the `LD_LIBRARY_PATH' environment variable 
    during execution 
    - add LIBDIR to the `LD_RUN_PATH' environment variable 
    during linking 
    - use the `-Wl,-rpath -Wl,LIBDIR' linker flag 
    - have your system administrator add LIBDIR to `/etc/ld.so.conf' 

See any operating system documentation about shared libraries for 
more information, such as the ld(1) and ld.so(8) manual pages. 
---------------------------------------------------------------------- 
chmod 755 $APACHE_HOME/modules/mod_test.so 
[activating module `test' in $APACHE_HOME/conf/httpd.conf] 

Предоставляя возможность -o вы можете избавиться от неопределенной ссылки на главное сообщение ошибки.

Смежные вопросы