我正在尝试创建一个Boost Python扩展,但更希望静态链接Boost Python库。否则,您需要在每台使用Python模块的计算机上安装完全相同版本的Boost。我没有使用bjam。
这在Linux(Ubuntu)中可以工作,但会导致动态链接:
这在Linux(Ubuntu)中可以工作,但会导致动态链接:
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 只是基本的示例代码:
#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);
}
有很多谷歌搜索结果,让我尝试了很多东西,但没有一个完全奏效。