以下の内容はhttps://end0tknr.hateblo.jp/entry/20151205/1449315930より取得しました。


pythonのctypesで、so (Shared Object)の関数を利用する

perlのxsと比較すると、かなり簡単な気がします

step1 - Cソースを作成

$ vi HelloCtypes.c

#include <stdio.h>

void hello_ctypes() {
  printf("HELLO CTYPES\n");
}

step2 - Cソースをコンパイル

$  gcc -shared -fPIC -o HelloCtypes.so HelloCtypes.c

step3 - python scriptを作成

$ vi call_ctypes.py

from ctypes import *

def main():
    so = cdll.LoadLibrary("./HelloCtypes.so")
    so.hello_ctypes()

if __name__ == "__main__":
    main()

step4 - 実行

$ python ./call_ctypes.py 
HELLO CTYPES



以上の内容はhttps://end0tknr.hateblo.jp/entry/20151205/1449315930より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14