我如何链接到libpython.a,例如运行时链接程序可以找到libpython.a中的所有符号? [英] How can I link against libpython.a such the runtime linker can find all the symbols in libpython.a?

查看:564
本文介绍了我如何链接到libpython.a,例如运行时链接程序可以找到libpython.a中的所有符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的续集问题中这个问题,我的公司环境缺少 libpython2.6.so 共享对象,但是有 libpython2.6.a 文件。有没有一种方法可以在 libpython2.6.a 中编译,同时保留 libpython2.6.a 这样动态库可以在运行时找到这些符号?



我目前使用静态库进行编译如下所示:

  g ++ -I / usr / CORP / pkgs / python / 2.6.2 / include / python2.6 \ 
〜/ tmp.cpp -pthread -lm -ldl -lutil \
/usr/CORP/pkgs/python/2.6.2/lib/python2.6/config/libpython2.6.a \
-o tmp.exe

然而,如果我加载一个像'数学'这样的模块,它将会消失:

 未定义符号:PyInt_FromLong 


解决方案

您需要将 - export-dynamic 传递给链接器。因此,从 g ++ 它是......

  g ++ -Wl, - export-dynamic ... 


In a sequel question to this question, my corporate environment lacks the libpython2.6.so shared object but has the libpython2.6.a file. Is there a way that I can compile in libpython2.6.a while retaining the symbols in libpython2.6.a such that dynamic libraries can find these symbols at runtime?

My current compile with the static library looks like:

g++ -I/usr/CORP/pkgs/python/2.6.2/include/python2.6 \
    ~/tmp.cpp -pthread -lm -ldl -lutil \
    /usr/CORP/pkgs/python/2.6.2/lib/python2.6/config/libpython2.6.a \
    -o tmp.exe

However, if I load a module like 'math', it dies with:

undefined symbol: PyInt_FromLong

解决方案

You need to pass --export-dynamic to the linker. So from g++ it's...

g++ -Wl,--export-dynamic ...

这篇关于我如何链接到libpython.a,例如运行时链接程序可以找到libpython.a中的所有符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆