用Boost Python进行静态链接 [英] Static linking with boost python

查看:135
本文介绍了用Boost Python进行静态链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建boost python扩展,但希望静态链接boost python库.否则,您需要在使用python模块的每台机器上安装与Boost完全相同的版本.我不是在用bjam.

I'm trying to create a boost python extension but would prefer to statically link the boost python libraries. Otherwise you need the exact same version of boost installed on every machine you use the python module. I'm not using bjam though.

这在linux(ubuntu)中有效,但会导致动态链接:

This works in linux (ubuntu) but results in dynamic linking:

g++ -o python_example.o -c python_example.cpp -Wall -fPIC -I/usr/include/python2.7
g++ -shared -o python_example.so python_example.o -lpython2.7 -lboost_python -lboost_system

python_example.cpp只是基本的示例代码:

python_example.cpp is just the basic example code:

#include <Python.h>
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include <boost/python.hpp>

char const* greet()
{
   return "hello, world";
}

BOOST_PYTHON_MODULE(python_example)
{
    using namespace boost::python;
    def("greet", greet);
}

很多Google搜索结果为我提供了很多尝试的机会,但是没有什么奏效的.

Lots of google results out there which gave me a lot of things to try but nothing that quite worked.

推荐答案

也许放一个

#define BOOST_PYTHON_STATIC_LIB

您源文件顶部的

会有所帮助吗?

on the top of your source file will help?

https://stackoverflow.com/a/35440164/9358910

这篇关于用Boost Python进行静态链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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