未定义的符号:Py_Initialize在Ubuntu 10.10

问题描述:

我创建了自己的Apache模块C API的Python。未定义的符号:Py_Initialize在Ubuntu 10.10

#include "httpd.h" 
#include "http_config.h" 
#include "http_protocol.h" 
#include "ap_config.h" 
#include "python2.7/Python.h" 
static char* a(){ 
Py_Initialize(); 
    PyRun_SimpleString("from time import time,ctime\n" 
        "print 'Today is',ctime(time())\n"); 
    Py_Finalize(); 
return "aba\t"; 
} 
/* The sample content handler */ 
static int mor_handler(request_rec *r) 
{ 
    if (strcmp(r->handler, "mor")) { 
     return DECLINED; 
    } 
    r->content_type = "text/html";  

    if (!r->header_only) 
    { char *d; 
    d= a(); 
ap_rputs(d, r); 
     ap_rputs("The sample page from mod_mor.c\n", r);} 
    return OK; 
} 

static void mor_register_hooks(apr_pool_t *p) 
{ 
    ap_hook_handler(mor_handler, NULL, NULL, APR_HOOK_MIDDLE); 
} 

/* Dispatch list for API hooks */ 
module AP_MODULE_DECLARE_DATA mor_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  */ 
    mor_register_hooks /* register hooks      */ 
}; 

但出现以下错误。我不明白。

/etc/init.d/apache2 restart 
apache2: Syntax error on line 203 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/mods-enabled/mor.load: Cannot load /usr/lib/apache2/modules/mod_mor.so into server: /usr/lib/apache2/modules/mod_mor.so: `undefined symbol: Py_Initialize` 
`Action 'configtest' failed`. 
The Apache error log may have more information. 
     ...fail! 
+0

你能运行'LDD/usr/lib中/的Apache2 /模块/ mod_mor.so'和后输出? – NPE

+1

你如何编译这个模块?你如何将一个对libpython.so的引用添加到你的模块中?你是否静态编译? – dsign

+0

1.apxs2 -cia mod_mor.c 2.我无法添加任何对libpython.so的引用。 –

您可以添加一个参考libpython:

$ apxs2 -cia mod_mor.c -lpython2.7 

那么你应该能够加载模。你不能指蟒蛇的动态。所以,你可以尝试使用图书馆的.A版本:

$ apxs2 -cia mod_mor.c -Wl,-static -lpython2.7 

但是,你可以得到一些抱怨,如果在libpython2.7.a对象不与-fPIC选项编译;我没有尝试。

+0

谢谢你非常非常** –

+0

欢迎您。我注意到,这可能是你的第一个问题,所以你可以“接受”这个答案,如果它是帮助你;-) – dsign

+0

我如何使用。一个版本库? Apache重启是确定的,但不显示任何东西。我使用** LoadModule intel_module /usr/lib/apache2/modules/mod_intel.so SetHandler intel **和** http:// localhost/intel ** –