![python中嵌入C語言腳本_第1頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/3/ae3730ab-166e-4e6d-a240-287370decf63/ae3730ab-166e-4e6d-a240-287370decf631.gif)
![python中嵌入C語言腳本_第2頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/3/ae3730ab-166e-4e6d-a240-287370decf63/ae3730ab-166e-4e6d-a240-287370decf632.gif)
![python中嵌入C語言腳本_第3頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/3/ae3730ab-166e-4e6d-a240-287370decf63/ae3730ab-166e-4e6d-a240-287370decf633.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、python中嵌入C語言腳本借助Cinpy和C語言解釋器TinyCC,可以在python程 序里面直接嵌入 C語言片斷、不經(jīng)編譯直接使用 C編寫的函 數(shù)了。win2k平臺上,簡單的測試對比數(shù)據(jù)如下(遞歸方法計算第 四十項兔子數(shù)列fib (40)語言實現(xiàn)時間(單位:秒)評python官方 純python fib 函數(shù)568.718天啊使用psyco加速的python fib 函數(shù)17.922比較接近,還行使用swig直接轉(zhuǎn)換的C語言編寫的模塊13.453使用Ci叩y嵌入fib函數(shù)11.532CVC6速度優(yōu)化編譯的可執(zhí)行文件5.562編譯的可執(zhí)行文件6.719解釋執(zhí)行6.813FreeBASICf
2、bc 0.16b-arch 486)-arch 686)編譯的可執(zhí)行文件(8.022編譯的可執(zhí)行文件(7.619forth4th 3.5a24th ex fib.4th277這個表現(xiàn)太失望了4th esv fib.4th fib.hx4th lx fib.hx1964th Ig fib.hx fib.eGforth-fast fib.gfth14.719不錯,不過不是說和 C的速度可以比嘛?怎么也就是優(yōu)化的 python的速度啊注:其余源程序freebasic function fib(x as integer) as integer if x&l t;=1 thenreturn 1e
3、lsereturn fib(x-1) + fib(x-2)end ifend functiondim starttime, endtime as doubledim res as integerstarttime=timerres=fib(40)endtime=timerprint "fib(40)= "resprint "time elapsed: " (endtime-starttime); " s"4th : fib ( x - y )dup 2 > ifdup 1 - recurseswap 2 - recurs
4、e +exitthendrop 1 ;time41 fib . crtimeswap -."time elapsed " . ." s" crgforth-0.6.2 : fib ( x - y )dup 2 > ifdup 1 - recurseswap 2 - recurse +exitthendrop 1 ;utime41 fib . crutime 2swap d-."time elapsed " d. ." us" cr如果在windows下使用mingw編譯當(dāng)前的TinyCC,嵌入C腳本會
5、報錯:tcc: file 7c/Program Files/tcc/libtcc1.a' not foundDoug Currie在tcc的郵件列表里面提供了一個補(bǔ)?。篐ere is what I did (and reported to the mailing list)last February,so the patch may not be accurate for more recentversions, but theissues are the same.I have been able to create a libtcc.dll for WinXP using MinG
6、W/MSYS;the changes that were necessary were very minor.Perhaps thisdescription will help others use libtcc on Windows.First, a small bug to report:In tcc.c the function tcc_basename() follows the line: #if !defined(LIBTCC)but the function tcc_basename() is used in pe_build_exports() intccpe.c - movi
7、ng the #if line below the function tcc_basename()eliminates a link error building libtcc.dll in PEtarget mode.Second, configuring and making tcc with MSYS places a pathname inconfig.h in MSYS format. For example, I passed theargument-prefix=/c/Dev/tccto configure; this path was good for building tcc
8、.exeand didn'tcontain any spaces, unlike the default path. Thiscreates the line#define CONFIG_TCCDIR "/c/Dev/tcc"in config.h. Manually changing this line to#define CONFIG_TCCDIR "C:/Dev/tcc"enables libtcc.dll to find the include files andlibraries once thelibrary is built. Th
9、e application tcc.exe avoids this problem bysetting tcc_lib_path from the application's directoryat startup. Asimilar solution could be used for the library usingDllMain.So, after configure, fix CONFIG_TCCDIFh config.h and make.Finally, the library libtcc.dll can be built with theMSYS command:gc
10、c -02 -shared -Wall -Wl,-export-all-symbols /-mpreferred-stack-boundary=2 /-march=i386 -falign-functions=0 -fno-strict-aliasing/-DTCC_TARGET_PE - DLIBTCC -o libtcc.dll tcc.cBelow is a diff of tcc-0.9.23 tcc.c and the changes forLIBTCC withTCC_TARGET_PE and DLL location of library files.Regards,e-./t
11、cc-0.9.23-o/tcc.c Fri Jun 17 18:09:152005+ tcc.c Tue Feb 28 17:03:44 2006 -10157,8 +10157,6 flag_name, value);-#if !defined(LIBTCC)/* extract the basename of a file */static const char *tcc_basename(const char *name) -10175,6 +10173,35 return p;+#if defined(LIBTCC)+#ifdef WIN32+int _stdcall DIIMain(
12、void * hinstDLL, unsigned long fdwReason, void *lpvReserved)+ if (fdwReason = 1/*DLL_PROCESS_ATTACH*/)+ +/* on Win32, as implemented in main()+ we suppose the lib and includes are at thelocation of this library+ */+static char path1024;+char *p,*d;+GetModuleFileNameA(hinstDLL, path, sizeofpath);+p = d = strlwr(pat
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2023八年級英語下冊 Unit 5 What were you doing when the rainstorm came說課稿 (新版)人教新目標(biāo)版
- 二零二五年度餐飲行業(yè)員工勞動合同(含培訓(xùn)協(xié)議)
- 二零二五年度新材料研發(fā)合作入股協(xié)議
- 二零二五年度2025年度生態(tài)旅游區(qū)場地合作經(jīng)營協(xié)議
- 二零二五年度美發(fā)店店長職位勞動合同(業(yè)績提成與考核細(xì)則)
- 2025年度連鎖店加盟會員積分體系合作協(xié)議
- 2025年度自助餐連鎖經(jīng)營授權(quán)合同
- 物業(yè)維修基金管理協(xié)議書(2篇)
- 2025年度稻谷期貨交易風(fēng)險管理合同
- 二零二五年度2025年度電焊工職業(yè)健康體檢合同
- (一模)寧波市2024學(xué)年第一學(xué)期高考模擬考試 數(shù)學(xué)試卷(含答案)
- 冀少版小學(xué)二年級下冊音樂教案
- 父母贈與子女農(nóng)村土地協(xié)議書范本
- 《師范硬筆書法教程(第2版)》全套教學(xué)課件
- 中國聯(lián)通H248技術(shù)規(guī)范
- 集團(tuán)母子公司協(xié)議書
- DL-T-692-2018電力行業(yè)緊急救護(hù)技術(shù)規(guī)范
- 2024年杭州錢塘新區(qū)建設(shè)投資集團(tuán)有限公司招聘筆試沖刺題(帶答案解析)
- 《電力系統(tǒng)自動化運維綜合實》課件-SDH設(shè)備尾纖連接
- 中醫(yī)病證診斷療效標(biāo)準(zhǔn)
- 愛國主義教育法 講座
評論
0/150
提交評論