728x90
반응형

1. cc complier 로 .so 생성 하기

[www@alpha clib]$ gcc -c -I/usr/include -I/usr/local/include/python3.6m -fPIC test_show_video.c
[www@alpha clib]$ ls
Makefile  test_show.py  test_show_video.c  test_show_video.o
[www@alpha clib]$ gcc -shared -fPIC -o test_show_video.so test_show_video.o
[www@alpha clib]$ ls
Makefile      test_show_video.c  test_show_video.so
test_show.py  test_show_video.o

 

2. .so 를 python 에서 import 하기 위한 모듈화 시키기

[www@alpha clib]$ vi setup.py
# setup.py
from distutils.core import setup, Extension
setup(name = "test_show_video",
version = "1.0",
description = "name",
author = "Samsjang",
author_email = "test@naver.com",  ## 회사 이메일
url = "http://www.naver.com",  ## 회사 url
ext_modules = [Extension("test_show_video", ["test_show_video.c"])]
)
[www@alpha clib]$ python setup.py install
running install
running build
running build_ext
building 'test_show_video' extension
creating build
creating build/temp.linux-x86_64-3.6
gcc -pthread -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -I/opt/rh/rh-python36/root/usr/include -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/home/www/test4/include -I/opt/rh/rh-python36/root/usr/include/python3.6m -c test_show_video.c -o build/temp.linux-x86_64-3.6/test_show_video.o
creating build/lib.linux-x86_64-3.6
gcc -pthread -shared -L/opt/rh/rh-python36/root/usr/lib64-Wl,-z,relro -Wl,-rpath,/opt/rh/rh-python36/root/usr/lib64 -Wl,--enable-new-dtags build/temp.linux-x86_64-3.6/test_show_video.o -L/opt/rh/rh-python36/root/usr/lib64 -lpython3.6m -o build/lib.linux-x86_64-3.6/test_show_video.cpython-36m-x86_64-linux-gnu.so
running install_lib
copying build/lib.linux-x86_64-3.6/test_show_video.cpython-36m-x86_64-linux-gnu.so -> /home/www/test4/lib64/python3.6/site-packages
running install_egg_info
Writing /home/www/test4/lib64/python3.6/site-packages/test_show_video-1.0-py3.6.egg-info
[www@alpha clib]$ !vi

 

3. 사용하기

[www@alpha clib]$ vi test_show.py
import test_show_video as sv
sv.on_videocam()
728x90
300x250

'IT > Misc Tip' 카테고리의 다른 글

DNS Lookup이나 Global Ping체크 시  (0) 2021.08.19
svn충돌 해결방법 (conflict문제)  (0) 2021.08.12
Mac에서 ansible 수행시 발생된 에러  (0) 2021.08.03
DNS 캐시 클리어  (0) 2021.07.30
CentOS7 Python3.6 & Django Install  (0) 2021.07.27

+ Recent posts