Static linking with boost python

我的梦境 提交于 2019-12-24 03:19:57

问题


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.

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 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);
}

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


回答1:


Maybe put a

#define BOOST_PYTHON_STATIC_LIB

on the top of your source file will help?

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



来源:https://stackoverflow.com/questions/29946400/static-linking-with-boost-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!