我使用distutils执行此操作,为了执行静态链接,我将libportaudio添加到extra\u objects参数中,如下所示:
module1 = Extension(
"demo",
sources=cppc,
# TODO remove os dependency
extra_compile_args=gccArgs,
# link against shared libraries
#libraries=[""]
# link against static libraries
extra_objects=["./clib-3rd-portaudio/libportaudio.a"]) # << I've added the static lib here
用“python”编译设置.py“生成”将导致以下链接器错误:
/usr/bin/ld:./clib-3rd-portaudio/libportaudio.a(pa_front.o):将R_X86_64_32重新定位到`。罗达塔.str1.8'不能在生成共享对象时使用;请使用-fPIC重新编译 /clib-3rd-portaudio/libportaudio.a:添加符号时出错:值错误 collect2:错误:ld返回1退出状态
因此,在这一点上,我尝试了显而易见的方法,将-fPIC标志添加到gccArgs中(注意上面的extra_compile_args=gccArgs),如下所示:
^{pr2}$但是这会导致完全相同的错误,所以我猜-fPIC标志不是根本原因。我可能遗漏了一些琐碎的东西,但我有点迷路了,希望有人能帮忙。在
正如错误消息所说,您应该使用
-fPIC
参数重新编译外部库libportaudio.a,而不是自己的代码。这就是为什么将-fPIC
添加到您的extra_compile_args
中没有帮助。在其他几个posts建议文件
libportaudio.a
不能用于构建共享库,这可能是因为portaudio
的默认生成设置不包括-fPIC
。在要正确地重新编译
portaudio
,请下载源代码并尝试使用-shared
选项运行./configure
(或类似的操作)。如果找不到正确的选项,请修改Makefile并将-fPIC
附加到额外的编译选项中。您还可以手动编译每个对象文件并将它们打包到libportaudio.a中因为你的目标文件(libdemo.so)是一个共享库,必须确保其中包含的任何目标代码都是用
-fPIC
选项编译的。要了解您为什么需要此选项,请参阅: What does -fPIC mean when building a shared library?和Position Independent Code (PIC) in shared libraries相关问题 更多 >
编程相关推荐