【发布时间】:2014-03-05 14:11:25
【问题描述】:
由于编译器错误,我在为 python 包装器编译 swig 的第一个教程示例时遇到问题。
我参考这个教程http://www.swig.org/Doc1.3/Python.html#Python_nn4
我创建了所有文件并执行了“31.2.3 手动编译动态模块”中指定的命令。
背景:我在 Windows 64 位系统的 cygwin 中使用 swig 和 gcc。
swig -python example.i
gcc -O2 -fPIC -c example.c
gcc -O2 -fPIC -c example_wrap.c -I/usr/include/python2.7/
这些命令可以正常工作。 在最后一步中,出现了很多错误。我玩了至少2个小时,找不到错误。我也包含了所有相关的 python-path,但错误仍然存在。
gcc -shared example.o example_wrap.o -o _example.so
example_wrap.o:example_wrap.c:(.text+0x4e): undefined reference to `PyArg_ParseTuple'
example_wrap.o:example_wrap.c:(.text+0x4e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `PyArg_ParseTuple'
example_wrap.o:example_wrap.c:(.text+0x79): undefined reference to `PyLong_AsLong'
example_wrap.o:example_wrap.c:(.text+0x79): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `PyLong_AsLong'
...
有人知道问题出在哪里吗?我想这与我在 cygwin 中的 gcc 中的编译器设置有关,但我无法让它工作。
提前致谢
【问题讨论】:
-
那些不是编译器错误,而是链接器错误。这意味着它找不到您(直接或间接)调用的某些函数。要解决它,您需要链接到包含这些文件的库。
-
来自 SWIG wiki 的 This entry 看起来可能是相关的。
标签: c gcc compiler-errors linker swig