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(<ime);
return ctime(<ime);
}
文件: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位不會改變任何東西:你可以找到一個「好」鏈接選項,但它在運行時崩潰。如何解決這個問題?