【发布时间】:2016-08-21 00:04:28
【问题描述】:
我正在尝试将“c++ portaudio 库”与我的“C++ 演示模块”静态链接,这是一个 python 可调用库(模块)。
我正在使用 distutils 执行此操作,为了执行静态链接,我已将 libportaudio 添加到 extra_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 setup.py build”编译会导致以下链接器错误:
/usr/bin/ld: ./clib-3rd-portaudio/libportaudio.a(pa_front.o): relocation R_X86_64_32 against `.rodata.str1.8' 不能在制作共享对象时使用;使用 -fPIC 重新编译 ./clib-3rd-portaudio/libportaudio.a:添加符号时出错:值错误 collect2:错误:ld 返回 1 个退出状态
所以此时我已经尝试了显而易见的方法,我已将 -fPIC 标志添加到 gccArgs(请注意上面的 extra_compile_args=gccArgs),如下所示:
gccArgs = [
"-Icsrc",
"-Icsrc/paExamples",
"-Icinc-3rd-portaudio",
"-Icinc-3rd-portaudio/common",
"-Icinc-3rd-portaudio/linux",
"-fPIC"] # << I've added the -fPIC flag here
但是这会导致完全相同的错误,所以我猜 -fPIC 标志不是根本原因。我可能遗漏了一些微不足道的东西,但我在这里有点迷路,希望有人能提供帮助。
【问题讨论】: