免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
boost_python寫擴(kuò)展

Boost版本號(hào)1.34.1

可以google并參考一篇叫"混合系統(tǒng)接口Boost.Python"的文章
還有
http://wiki.python.org/moin/boost.python/HowTo


http://learn.tsinghua.edu.cn:8080/2005212716/html/boost_python.html


http://visnuhoshimi.spaces.live.com/blog/cns%2135416B2A4DC1B31B%211863.entry



1.bjam python
2.把生成*.lib復(fù)制到庫目錄(可以在djam的輸出中看到路徑)
3.
進(jìn)入Boost目錄下的“l(fā)ibs\python\build\VisualStudio”子目錄中,在VC中打開其中的“boost_python.dsw”文件。
分別編譯Boost.Python的Debug和Release版。
編譯完成后將在Boost目錄下的“l(fā)ibs \python\build\bin-stage”子目錄中生成動(dòng)態(tài)鏈接庫和庫文件復(fù)制出來
4.
    設(shè)置好包含文件,庫的路徑
    有以下內(nèi)容:
        python的include和lib
        boost的include以及上面生成的lib
       
5.
VC中
    項(xiàng)目->配置屬性->常規(guī)->配置類型 改為.dll
6.
編譯
char const* greet()
{
   return "hello, world";
}

#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
using namespace boost::python;

BOOST_PYTHON_MODULE(hello)
{
    def("greet", greet);
}

將生成的dll改名為hello.pyd
可以復(fù)制到python25\dlls下面,也可以在當(dāng)前目錄
結(jié)合步驟3生成的dll就可以看到輸出了

import hello
print hello.greet()
raw_input()

7.
封裝一下,把參數(shù)和返回值都封裝成python的類型,

#include <boost/python.hpp>
//先包含字典
#include <boost/python/dict.hpp>
class SearchPy{
    ...
    dict search(char* content){
        vector<string,int> result=_search.search(content);
        dict k_c;
        //將原來的返回值封裝成Python的字典格式
        for(vec_key_ptr::iterator i=result.begin();i!=result.end();++i)
            k_c.setdefault(i->keyword,i->count);
        return k_c;
    }
};

BOOST_PYTHON_MODULE(search){

   class_<SearchPy>("Search", init<>())
         .def("search", &SearchPy::search)
        //............................
    ;

}

ok,大功告成,可以在python中掉C++了

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
VC6.0下正確配置boost庫使用正則表達(dá)式(總編)
動(dòng)態(tài)鏈接 boost 庫,犯了個(gè)2B錯(cuò)誤
(原創(chuàng))compile cortex-vfx on Ubuntu10.04
boost 1.45.0 的安裝及測(cè)試(Visual Studio 2010)
VC 中使用MATLAB的C 數(shù)學(xué)庫和MCC生成的程序
很好的c 和Python混合編程文章
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服