boost 1.34 終于簡化了內嵌python的支持。
還支持了python2.5。
在中文windows下用vc8編譯boost的過程中,雖然仍有代碼頁字符警告,但是可以正常編譯成功,不再象1.33.1那樣造成正則表達式庫不修改源碼不能夠編譯通過的問題了。
下面的例子是從boost文檔中來的:
#include <iostream>
#include <string>
#include <boost/python.hpp>
#include <boost/ref.hpp>
#include <vector>
using namespace boost::python;
void greet()
{
object main = import("__main__");
object global(main.attr("__dict__"));
// Define greet function in Python.
object result = exec(
"def greet(a): \n"
" return 'Hello %s from Python!' % a \n",
global, global);
object greet = global["greet"];
list lst;
lst.append(1);
lst.append(2);
object r = greet(lst);
std::string message = extract<std::string>(r);
std::cout << message << std::endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
Py_Initialize();
greet();
system("Pause");
return 0;
}
BTW:
我用vc8編譯了全部的boost,然后,include加上lib目錄(內僅有lib和dll文件),合計2.68GB。