與python
CTYPES模塊是Python標準庫的一部分,為此任務提供了穩定且可廣泛的解決方案。與其他綁定方法不同,CTYPES不依賴於對其進行編譯的Python版本,從而確保與各種Python安裝的兼容性。 考慮以下代碼片段:要與Python連接起來,我們必須將功能聲明為extern“ c”,才能使CTYPE識別它們:
extern“ c” { foo* foo_new(){返回new foo(); } void foo_bar(foo* foo){foo-> bar(); } }最後,我們從ctypes import import import Cdll創建了一個Python wrapper:
With this wrapper, we can interact with our C library in Python:
f = Foo() f.bar()#打印到標準輸出
的“ hello”免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3