I've built the static python using this tutorial:(python version 3.4.2)
Everything works ,well almost. when My simple test application link with the library:
libpython3.4m.a
This is the source code of the simple demo:
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;
}
The problem is here that When I run the demo,it says :
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
Then I copy Lib directory from python directory to the demo directory,then before I run my application I export this:
export PYTHONPATH="Lib/"
Then the problem has gone,but here is the question:
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?