python
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| python [2014/12/28 08:38] – created donghee | python [2018/07/18 14:10] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | python | + | ====== Python C/C++ bindng |
| + | 간단한 cad를 만들어 보는게 목표 | ||
| + | - glfw, glew을 binding 하여 써보자. | ||
| + | - geode 분석 | ||
| + | - cygl 분석 https:// | ||
| + | |||
| + | ===== Cython helloworld ===== | ||
| - | ====== Cython helloworld ====== | ||
| Reference: https:// | Reference: https:// | ||
| - | setup.py | + | setup.py |
| < | < | ||
| from distutils.core import setup | from distutils.core import setup | ||
| Line 15: | Line 20: | ||
| </ | </ | ||
| - | hello.pyx | + | hello.pyx |
| < | < | ||
| def say_hello_to(name): | def say_hello_to(name): | ||
| Line 31: | Line 36: | ||
| </ | </ | ||
| 를 해서 커맨드라인에서 hello.c를 생성할 수 있다. | 를 해서 커맨드라인에서 hello.c를 생성할 수 있다. | ||
| + | |||
| + | ---- | ||
| + | 질문 | ||
| + | - pyx, pyd, pyi 의 역활 구분. | ||
| + | |||
| + | |||
| + | ---- | ||
| + | ===== Cython Compiler ===== | ||
| + | |||
| + | win32에서 cythonize할때 사용하는 컴파일러는 mingw32와 ms의 visual c++이 있는데, ms에서 python용으로 vc를 준다. | ||
| + | |||
| + | [[http:// | ||
| + | |||
| + | ---- | ||
| + | ===== Cython Tutorial ===== | ||
| + | |||
| + | # Cython Tutorial 2015-1-1 | ||
| + | |||
| + | install | ||
| + | |||
| + | Dockerfile | ||
| + | < | ||
| + | FROM debian:sid | ||
| + | MAINTAINER Donghee Park < | ||
| + | |||
| + | RUN apt-get update | ||
| + | CMD echo " | ||
| + | RUN apt-get install vim python openssh-server -y | ||
| + | CMD echo "vim and ssh package installed" | ||
| + | RUN echo " | ||
| + | RUN echo ' | ||
| + | RUN / | ||
| + | RUN apt-get install build-essential python-pip python-dev -y | ||
| + | RUN pip install cython | ||
| + | |||
| + | CMD ["/ | ||
| + | |||
| + | # | ||
| + | </ | ||
| + | |||
| + | Makefile | ||
| + | |||
| + | < | ||
| + | cython helloworld.pyx | ||
| + | gcc -g -O2 -fpic `python-config --cflags` -c helloworld.c -o helloworld.o | ||
| + | gcc -shared -o helloworld.so helloworld.o `python-config --libs` | ||
| + | |||
| + | </ | ||
| + | |||
| + | mycode.c | ||
| + | |||
| + | < | ||
| + | #include < | ||
| + | |||
| + | int myfunc(int a, int b) | ||
| + | { | ||
| + | printf(" | ||
| + | return a+b; | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | mycode.h | ||
| + | |||
| + | < | ||
| + | #ifndef __MYCODE_H__ | ||
| + | #define __MYCODE_H__ | ||
| + | extern int myfunc (int, int); | ||
| + | #endif __MYCODE_H__ | ||
| + | </ | ||
| + | |||
| + | mycodecpy.pyx | ||
| + | |||
| + | < | ||
| + | cdef extern from " | ||
| + | cdef int myfunc (int, int) | ||
| + | |||
| + | def callCfunc (): | ||
| + | print myfunc (1,2) | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | cython mycodecpy.pyx | ||
| + | gcc -g -O2 -fpic -c mycode.c -o mycode.o | ||
| + | gcc -g -O2 -fpic -c mycodecpy.c -o mycodecpy `python-config --cflags` | ||
| + | gcc -shared -o mycodecpy.so mycode.o mycodecpy.o `python-config --libs` | ||
| + | </ | ||
| + | |||
| + | ---- | ||
| + | ===== xdress install ===== | ||
| + | llvm 3.4.2 in macos x 10.9 | ||
| + | |||
| + | < | ||
| + | wget http:// | ||
| + | #wget http:// | ||
| + | |||
| + | tar xvfz clang+llvm-3.4.2-x86_64-apple-darwin10.9.xz | ||
| + | mv clang+llvm-3.4.2-x86_64-apple-darwin10.9 llvm-3.4.2-build | ||
| + | |||
| + | export LLVM_CONFIG=llvm-3.4.2-build/ | ||
| + | |||
| + | git clone git:// | ||
| + | |||
| + | cd xdress | ||
| + | |||
| + | python setup.py build_ext --inplace | ||
| + | sudo python setup.py install | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | < | ||
| + | xdress --debug -p clang | ||
| + | |||
| + | </ | ||
| + | ---- | ||
| + | ===== xdress 사용하기 ===== | ||
| + | |||
| + | c++ class ' | ||
| + | |||
| + | |||
| + | jehsrc/ | ||
| + | < | ||
| + | #if !defined(HOOVER) | ||
| + | #define HOOVER | ||
| + | namespace hoover { | ||
| + | class A { | ||
| + | | ||
| + | float a; | ||
| + | | ||
| + | };}; | ||
| + | #endif | ||
| + | </ | ||
| + | ---- | ||
| + | |||
| + | jehsrc/ | ||
| + | |||
| + | < | ||
| + | #include " | ||
| + | double hoover:: | ||
| + | int i = 1; | ||
| + | double val = a; | ||
| + | while (i < n){val *= a; i++;}; | ||
| + | return val; | ||
| + | }; | ||
| + | </ | ||
| + | |||
| + | |||
| + | ---- | ||
| + | |||
| + | jeh_xdressrc.py | ||
| + | |||
| + | < | ||
| + | package = ' | ||
| + | packagedir = ' | ||
| + | builddir = ' | ||
| + | |||
| + | classes = [(' | ||
| + | </ | ||
| + | |||
| + | jeh_setup.py | ||
| + | < | ||
| + | import os | ||
| + | from distutils.core import setup | ||
| + | from distutils.extension import Extension | ||
| + | from Cython.Distutils import build_ext | ||
| + | |||
| + | import numpy as np | ||
| + | |||
| + | cwd = os.getcwd() | ||
| + | incdirs = [cwd, os.path.join(cwd, | ||
| + | |||
| + | ext_modules = [ | ||
| + | Extension(" | ||
| + | include_dirs=incdirs, | ||
| + | ] | ||
| + | |||
| + | setup( | ||
| + | name = ' | ||
| + | cmdclass = {' | ||
| + | ext_modules = ext_modules, | ||
| + | packages = [' | ||
| + | ) | ||
| + | </ | ||
| + | |||
| + | Makefile | ||
| + | |||
| + | < | ||
| + | all: | ||
| + | xdress --rc jeh_xdressrc.py | ||
| + | python jeh_setup.py build > /dev/null 2>&1 | ||
| + | clean: | ||
| + | rm -rf build | ||
| + | rm -rf jehbuild | ||
| + | | ||
| + | </ | ||
| + | |||
| + | ---- | ||
| + | Hoover Example | ||
| + | |||
| + | < | ||
| + | from jedgar.hoover import A | ||
| + | |||
| + | a = A() | ||
| + | a.a = 10 | ||
| + | a.power(42) | ||
| + | </ | ||
python.1419755905.txt.gz · Last modified: 2018/07/18 14:09 (external edit)