先写一个简单的py程序:helloworld.py
#!/usr/local/services/python/bin/python
# -*- coding: utf-8 -*-
import traceback
def hello():
#traceback.print_stack(file=sys.stdout)
print "hello world"
然后来写我们的c++代码:py.cpp
> g++ test.cpp -o test -I/usr/include/python2.6 -lpython2.6
> ./test
hello world
然后是makefile:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
CXX = g++
TARGET = py
C_FLAGS += -g -Wall
INC = -IC:/Python27/include/
LIB = -LC:/Python27/libs/ -lpython27
all: $(TARGET)
py: py.o
$(CXX) -o $@ $^ $(LIB) $(C_FLAGS)
.cpp.o:
$(CXX) -c -o $*.o $(INC) $(C_FLAGS) $*.cpp
clean:
-rm -f *.o $(TARGET)
|