静态链接python模块的麻烦

时间:2014-04-08 02:52:15

标签: python c++ gcc

我正在使用SWIG将一些C ++打包成python模块。我正在尝试使用静态链接库来构建它,以便它可以部署到具有旧glibc / libc ++ /等的系统。我可以将libgcc和libstdc ++转换为静态链接但我无法想办法针对glibc的静态链接。谷歌解决方案似乎是静态链接整个可执行文件或告诉我不要这样做......

无论如何,这是我setup.py

的重要部分
cargs = ['-O3','-fPIC','-std=c++11']
largs = ['-lgsl','-lgslcblas','-static-libgcc','-static-libstdc++','-Bstatic -lc']

StopPow_module = Extension('_StopPow',
                        sources=['StopPow_wrap.cxx', '../src/StopPow.cpp', '../src/StopPow_Plasma.cpp', '../src/StopPow_PartialIoniz.cpp','../src/StopPow_SRIM.cpp', '../src/StopPow_BetheBloch.cpp', '../src/StopPow_LP.cpp', '../src/StopPow_AZ.cpp','../src/StopPow_Mehlhorn.cpp','../src/StopPow_Grabowski.cpp','../src/StopPow_Zimmerman.cpp','../src/StopPow_BPS.cpp','../src/AtomicData.cpp','../src/PlotGen.cpp', '../src/Spectrum.cpp'],
                        extra_compile_args = cargs,
                        extra_link_args = largs,
                        language="c++" )

setup (name = 'StopPow',
   version = '0.2',
   description = """Stopping power library""",
   ext_modules = [StopPow_module],
   py_modules = ["StopPow","StopPow_Plasma","StopPow_PartialIoniz","StopPow_SRIM","StopPow_BetheBloch","StopPow_LP","StopPow_AZ","StopPow_Mehlhorn","StopPow_Grabowski","StopPow_Zimmerman","StopPow_BPS","AtomicData","PlotGen","Spectrum"],
   )

哪个构建正常但仍需要libc(在其他几个中):

ldd _StopPow.cpython-33m.so 
    linux-vdso.so.1 =>  (0x00007fff309fe000)
    libgsl.so.0 => /usr/lib/libgsl.so.0 (0x00007f99e8c0b000)
    libgslcblas.so.0 => /usr/lib/libgslcblas.so.0 (0x00007f99e89bf000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f99e86ba000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f99e849d000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f99e80d5000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f99e941c000)

libgsl没问题,但是如何让它与其他人静态链接呢?

0 个答案:

没有答案