Python から C の呼出し – 2
先日 Python から C を呼び出す関係を調べていて Synology NAS に Python.h がなかった.
検索 をかけると DSM「パッケージ センター」-「Python3」では python-dev が入ってないらしい.
次の様な手順で python-dev をインストール.
# sudo -i
# cd /var/services/homes/Iwao/
# source ./set_ds_inc.sh
# opkg install python-dev
# opkg install python3-dev
コンパイルで必要なファイルは次の所に入った.
/volume1/@entware-ng/opt/include/python3.6/Python.h
/volume1/@entware-ng/opt/include/python2.7/Python.h
Iwao@DS116:~/pyt_test/call_c/call_cpp/g3d_to$ g++ g3d_to.cpp -Wall -fPIC -o g3d_to.so -shared g3d_to.cpp:9:20: fatal error: Python.h: No such file or directory ^ compilation terminated. Iwao@DS116:~/pyt_test/call_c/call_cpp/g3d_to$ g++ g3d_to.cpp -Wall -fPIC -o g3d_to.so -shared -I /volume1/@entware-ng/opt/include/python3.6/ Iwao@DS116:~/pyt_test/call_c/call_cpp/g3d_to$ ll total 9568 drwxrwxrwx+ 3 Iwao users 4096 Aug 5 10:29 . drwxrwxrwx+ 3 Iwao users 4096 Aug 5 09:50 .. -rwxrwxrwx+ 1 Iwao users 3941375 May 7 18:03 3887.imo -rwxrwxrwx+ 1 Iwao users 1241865 Jul 7 15:13 7801.imo drwxrwxrwx+ 2 Iwao users 4096 Aug 5 10:29 bak -rwxrwxrwx+ 1 Iwao users 1688 Aug 4 15:04 g3d_to.cpp -rwxrwxrwx 1 Iwao users 2654136 Aug 5 10:29 g3d_to.so -rwxrwxrwx+ 1 Iwao users 1644 Aug 7 2019 gons_to.cpp -rwxrwxrwx 1 Iwao users 1931244 Aug 5 10:17 gons_to.out Iwao@DS116:~/pyt_test/call_c/call_cpp/g3d_to$ python3 Python 3.6.2 (default, Jan 11 2018, 10:32:53) [GCC 6.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import g3d_to >>> dir(g3d_to) ['__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'gons_to', 'load', 'save'] >>> g3d_to.load("./7801.imo") >>> g3d_to.save("./7801.stl") >>> g3d_to.save("./7801.ac") >>> Iwao@DS116:~/pyt_test/call_c/call_cpp/g3d_to$ ll total 10252 drwxrwxrwx+ 3 Iwao users 4096 Aug 5 10:31 . drwxrwxrwx+ 3 Iwao users 4096 Aug 5 09:50 .. -rwxrwxrwx+ 1 Iwao users 3941375 May 7 18:03 3887.imo -rwxrwxrwx+ 1 Iwao users 438369 Aug 5 10:31 7801.ac -rwxrwxrwx+ 1 Iwao users 1241865 Jul 7 15:13 7801.imo -rwxrwxrwx+ 1 Iwao users 254784 Aug 5 10:31 7801.stl drwxrwxrwx+ 2 Iwao users 4096 Aug 5 10:29 bak -rwxrwxrwx+ 1 Iwao users 1688 Aug 4 15:04 g3d_to.cpp -rwxrwxrwx 1 Iwao users 2654136 Aug 5 10:29 g3d_to.so -rwxrwxrwx+ 1 Iwao users 1644 Aug 7 2019 gons_to.cpp -rwxrwxrwx 1 Iwao users 1931244 Aug 5 10:17 gons_to.out Iwao@DS116:~/pyt_test/call_c/call_cpp/g3d_to$