use*_*003 5 c++ python gcc boost
我已经使用本教程构建了静态 python:(python 版本 3.4.2)
一切正常,几乎。当我的简单测试应用程序与库链接时:
libpython3.4m.a
这是简单演示的源代码:
using namespace boost::python;
using namespace std;
class World {
private:
string name;
public:
void set(string name) {
this->name = name;
}
void greet() {
printf("name is %s\n", this->name.c_str());
}
};
typedef boost::shared_ptr< World > world_ptr;
BOOST_PYTHON_MODULE(hello) {
class_<World>("World")
.def("greet", &World::greet)
.def("set", &World::set)
;
};
int main ( int argc, char** argv ) {
Py_NoSiteFlag = 1;
Py_FrozenFlag = 1;
//Py_IgnoreEnvironmentFlag = 1;
Py_SetPythonHome(L".");
Py_SetProgramName(L"");
PyImport_AppendInittab("hello",PyInit_hello);
Py_Initialize();
try {
PyRun_SimpleStringFlags("import hello", NULL);
PyRun_SimpleStringFlags("ha = hello.World()", NULL);
PyRun_SimpleStringFlags("ha.set('tango')", NULL);
PyRun_SimpleStringFlags("ha.greet()", NULL);
}
catch(error_already_set) {
PyErr_Print();
}
Py_Finalize();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
问题是当我运行演示时,它说:
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
Run Code Online (Sandbox Code Playgroud)
然后我将 Lib 目录从 python 目录复制到 demo 目录,然后在运行我的应用程序之前我导出这个:
export PYTHONPATH="Lib/"
Run Code Online (Sandbox Code Playgroud)
然后问题就解决了,但这里是问题:
Can I compile all the package in the Lib to static library libpython3.4m.a? so that I don't have to carry Lib files?
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
650 次 |
| 最近记录: |