2009-11-14 78 views
2

SWIG可以在AIX上輕鬆編譯和安裝。不幸的是,一個簡單的SWIG hello world(它也編譯 - 但不是那麼容易)崩潰與分段錯誤或非法指令(取決於編譯/鏈接器過程的一些細節)。 gcc和xlc(IBM c編譯器)都會發生這種情況。我只嘗試了本地AIX鏈接器ld,因爲同名的GNU ld沒有安裝在我的系統上。SWIG在AIX上崩潰(使用python,可能還有其他所有SWIG支持)

文件:example.c

#include <time.h> 
double My_variable = 3.0; 

int fact(int n) { 
    if (n <= 1) return 1; 
    else return n*fact(n-1); 
} 

int my_mod(int x, int y) { 
    return (x%y); 
} 

char *get_time() 
{ 
    time_t ltime; 
    time(&ltime); 
    return ctime(&ltime); 
} 

文件:example.i

%module example 
%{ 
/* Put header files here or function declarations like below */ 
extern double My_variable; 
extern int fact(int n); 
extern int my_mod(int x, int y); 
extern char *get_time(); 
%} 

extern double My_variable; 
extern int fact(int n); 
extern int my_mod(int x, int y); 
extern char *get_time(); 

生成文件片段:

swig -python example.i 
xlc -q64 -c example.c example_wrap.c -I/your-python-path/include/python2.5/ 
ld -G -b64 -berok -bnoentry -bexpall -brtl example.o example_wrap.o -o _example.so 

接頭步驟是有問題的一個。如果你遵循的tutorial的例子,你應該做的

ld -bshared example.o example_wrap.o -o _example.so #the b is not a typo, but a different syntax in AIX vd GNU ld 

不幸的是,這並不有以下幾個原因工作。我相信IBM/AIX和開源社區對「共享庫」意味着什麼有不同的想法。從AIX本機鏈接器獲得的最常見的共享對象(所以)根本沒有符號(實際上小於1kB)。它也很容易得到鏈接器壞了輸出(在這種情況下,一個相當長將出現如下未解決的符號列表,同時連接):

ld: 0711-317 ERROR: Undefined symbol: PyType_Type 

做什麼一個supposed to do,它似乎很清楚,該解決方案使用各種鏈接器選項進行黑客攻擊:-berok,-bnoentry,-bexpall,-brtl,-bshared,-bM:SRE,-bexpfull。實際上,可以找到一些組合,這些組合可以創建非空的.so庫,而不會產生錯誤。上面的Makefile代碼段中會報告其中的一種組合(還有其他組件)。不幸的是,他們都失敗了以下兩種模式之一!

$ python -c "import example" 
Illegal instruction (core dumped) 

$ python -c "import example" 
Segmentation fault (core dumped) 

使用GCC或不同版本的Python(我們有7!)無論是32位或64位不會改變任何東西:你可以找到一個「好」鏈接選項,但它在運行時崩潰。如何解決這個問題?

回答

0

這不是一個真正的問題,而是一個關於我如何解決問題的報告(請參閱here爲什麼我這樣做)。實際上我自己無法解決,但是這要歸功於this other guy。我在這裏重寫它,因爲他太具體了(AIX 5.1中有perl和C++,當我尋找其他東西的時候,我發現他是偶然的!當我尋找這個時,我一直無法找到他的答案問題!我希望這篇文章對其他人更容易找到 我的問題是在AIX 5.3上使用python和C.我相信它在AIX上安裝每個SWIG都是常見的(因此我沒有標記python和C)。我們會盡快與開發人員聯繫,以便他們可以首先解決問題。

好了,解決方法是簡單地使用不同的連接線,特別是如下:

ld -G -bI:/your-python-path/lib/python2.5/config/python.exp -bnoentry -bexpall -lC -lc -ldl example.o example_wrap.o -o _example.so 

的關鍵是EXP文件,你會發現自己的語言/安裝:

find /your-python-or-perl-or-other-language-path/ -name *exp 

希望這有助於!