Import SWIG导入错误:未定义的符号:\u Py\u RefTotal

Import SWIG导入错误:未定义的符号:\u Py\u RefTotal,import,swig,Import,Swig,我真的是个新手。我试图编译SWIG中给出的示例,但出现以下错误: $ python Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [GCC 4.4.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import example Traceback (most recent call last):

我真的是个新手。我试图编译SWIG中给出的示例,但出现以下错误:

$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import example
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "example.py", line 25, in <module>
    _example = swig_import_helper()
  File "example.py", line 21, in swig_import_helper
    _mod = imp.load_module('_example', fp, pathname, description)
ImportError: ./_example.so: undefined symbol: _Py_RefTotal
$python
Python 2.6.5(r265:79063,2010年4月16日,13:09:56)
[GCC 4.4.3]关于linux2
有关详细信息,请键入“帮助”、“版权”、“信用证”或“许可证”。
>>>导入示例
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“example.py”,第25行,在
_示例=swig\u import\u helper()
swig\u import\u helper中第21行的文件“example.py”
_mod=imp.load_模块(“示例”,fp,路径名,描述)
导入错误:./\u示例。so:未定义符号:\u Py\u RefTotal

我也遇到了类似的问题,谷歌把我送到了这里——我想我会发布我的解决方案

对于编译器来说,对于使用C还是C++,

感到困惑。 <> P>因为我打算写C++,我遵循了这个例子,但是使用了Swing -C++选项,并使用G++而不是GCC作为编译器。p> 但是,, 我的构建工具(boost.build或bjam)看到了“example.c”,并使用

g++-xc-O2-fPIC-c示例.c

“-Xc”标志指定了c代码,bjam由于example.c的文件扩展名而包括了该代码。这导致链接以类似于帮助请求的方式发出咯咯声

我将“example.c”的名称改为“example.cpp”(在使用bjam时会删除-Xc标志),然后链接就可以继续了

我花了一点时间才发现这一点,所以也许有一天我会为某人节省30分钟

祝福


Tom

你忘了在链接器语句中添加
-lpython2.6

成功了。我已经复制并粘贴了相同的代码,并进行了编译。现在可以用了