回答編集履歴

1

ためしたものを追加

2017/03/25 00:02

投稿

raccy
raccy

スコア21735

test CHANGED
@@ -1 +1,33 @@
1
1
  Pyhonのライブラリが指定されていないようです。`python-config --ldflags`で出力されるオプションを指定してみてください。
2
+
3
+
4
+
5
+ 私の環境では以下のような感じでコンパイルして、使用できました。(PythonはHomebrewで入れた2.7を使用しています)
6
+
7
+
8
+
9
+ ```
10
+
11
+ $ g++ -Wall -O2 -fpic `python-config --include` -c hello.cpp
12
+
13
+ $ g++ -shared -o hello.so `python-config --ldflags` -lboost_python hello.o
14
+
15
+ $ python
16
+
17
+ Python 2.7.13 (default, Dec 18 2016, 07:03:39)
18
+
19
+ [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
20
+
21
+ Type "help", "copyright", "credits" or "license" for more information.
22
+
23
+ >>> import hello
24
+
25
+ >>> hello.add(1, 2)
26
+
27
+ 3
28
+
29
+ >>> exit()
30
+
31
+ ```
32
+
33
+