2011-12-13 57 views
0

我創建了自己的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的引用。 –

回答

1

您可以添加一個參考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 ** –