SWIG在AIX上崩溃(使用python,可能还有其他所有SWIG支持) [英] SWIG crashes on AIX (with python, and probably everything else SWIG support)

查看:125
本文介绍了SWIG在AIX上崩溃(使用python,可能还有其他所有SWIG支持)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SWIG可以在AIX上轻松编译和安装。不幸的是,一个简单的 SWIG hello world (也可以编译-但不太容易)因分段而崩溃错误或非法指令(取决于编译/链接器过程的某些详细信息)。 gcc和xlc(IBM c编译器)都会发生这种情况。我只尝试了本机AIX链接程序ld,因为我的系统上未安装同名GNU ld。

SWIG compiles and install easily on AIX. Unfortunately, a simple SWIG hello world (which also compiles - but not so easily) crashes with Segmentation Fault or Illegal Instruction (depending on some details of the compilation/linker process). This happens with both gcc and xlc (IBM c compiler). I tried only the native AIX linker ld, because the homonyms GNU ld was not installed on my system.

文件:example.c

File: 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

File: 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();

Makefile片段:

Makefile snippet:

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

The链接器步骤是有问题的步骤。如果您按照教程上的示例进行操作,则应该

The linker step is the problematic one. If you follow the examples on the tutorial, you should do

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本机链接程序获得的最常见的共享库(so)中根本没有符号(实际上,其大小小于1kB)。从链接器中断开输出也是很容易的(在这种情况下,链接时会出现很长的未解析符号列表,如下所示):

Unfortunately this does not work for several reasons. I believe that IBM/AIX and the Open Source communities have quite a different thoughts on what "shared library" means. The most common shared objects (so) that you get from the AIX native linker have no symbols at all in them (and are in fact less than 1kB in size). It's also pretty easy to get broken output from the linker (in such a case a quite long list of unresolved symbols like the following appears while linking):

ld: 0711-317 ERROR: Undefined symbol: PyType_Type

做什么是什么< a href = http://en.wikipedia.org/wiki/RTFM rel = nofollow noreferrer>本来应该做的,看来解决方案显然是利用各种链接器选项 -berok -知识型 -bexpall -brtl -bshared -bM:SRE -bexpfull 。实际上,可以找到一些创建非空.so库的组合,而不会产生错误。这些组合之一在上面的Makefile代码段中报告(还有其他)。不幸的是,它们都无法在以下两种模式之一中失败!

Doing what one is supposed to do, it seems clear that the solution is hacking with the various linker options, -berok, -bnoentry, -bexpall, -brtl, -bshared, -bM:SRE, -bexpfull. In fact, it is possible to find some combinations which create a non-empty .so library, without generating errors. One of these combinations is reported in the Makefile snippet above (there are others). Unfortunately, all of them fail in one of the following two modes!

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

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

使用gcc或其他版本的python(我们有7!),无论是32位还是64位都不会改变任何内容:您可以找到好链接选项,但在运行时会崩溃。

Using the gcc, or a different version of python (we have 7!) either 32 bit or 64 bit does not change anything: you can find a "good" link option, but it crashes at runtime. How to solve this?

推荐答案

这不是一个实际的问题,而是有关如何解决问题的报告(请参见此处为什么我这样做)。实际上我自己无法解决问题,但这要感谢另一个人。我在这里重写它,因为他太具体了(使用Perl和C ++的AIX 5.1,当我在寻找其他东西时,我偶然发现了他!我在寻找这个东西时根本找不到他的答案。问题!我希望这篇文章可以为其他人找到!
我的问题是在AIX 5.3上使用python和C。我相信这对AIX上的每个SWIG安装都是很常见的(因此我没有标记python和C ),我会尽快与开发人员联系,以便他们可以首先修复帮助。

This is not an actual question, but a report on how I fixed my problem (see here why I'm doing this). And actually I wasn't able to solve it myself, but it was thanks to this other guy. I am rewriting it here, because he was too specific (AIX 5.1 with perl and C++, and I found him serendipitously, while I was searching for something else! I wasn't able to find his answer at all when I was searching for this problem! I hope this post will be more findable to others! My problem is on AIX 5.3 with python and C. I believe that it is common to every SWIG installation on AIX (thus I didn't tag python and C). I'll contact the developers soon so they might fix the help in the first place.

好吧,解决方法是简单地使用不同的链接行,尤其是如下所示:

Well, the fix is simply to use a different link line, in particular as follows:

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文件,您应该根据自己的语言/安装情况找到自己的文件:

The key is the exp file, which you should find yourself for your language/installation:

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

希望这会有所帮助!

这篇关于SWIG在AIX上崩溃(使用python,可能还有其他所有SWIG支持)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆