質問編集履歴

1

指摘していただいたことを踏まえました。

2018/10/21 12:04

投稿

inoshishi
inoshishi

スコア17

test CHANGED
File without changes
test CHANGED
@@ -334,6 +334,82 @@
334
334
 
335
335
 
336
336
 
337
+ ###試したことその2
338
+
339
+ boost.pythonのチュートリアルを説明しているページを元に以下を試しました。
340
+
341
+ [Boost.Python の機能をざっと紹介してみる](http://d.hatena.ne.jp/moriyoshi/20091214/1260779899)
342
+
343
+ ```C++
344
+
345
+ #include <boost/python.hpp>
346
+
347
+
348
+
349
+ int add(int lhs, int rhs)
350
+
351
+ {
352
+
353
+ return lhs + rhs;
354
+
355
+ }
356
+
357
+
358
+
359
+ BOOST_PYTHON_MODULE(basic)
360
+
361
+ {
362
+
363
+ using namespace boost::python;
364
+
365
+ def("add", &add);
366
+
367
+ }
368
+
369
+
370
+
371
+ ```
372
+
373
+ これを作って
374
+
375
+ ```cmd
376
+
377
+ takehiro@takehiro-desktop:~/ドキュメント$ g++ -DPIC -shared -fPIC -o basic.so basic.cpp -I/usr/include/python3.5m -lboost_python3
378
+
379
+ >>> import basic
380
+
381
+ >>> basic.add(1,2)
382
+
383
+ 3
384
+
385
+ >>> quit()
386
+
387
+ takehiro@takehiro-desktop:~/ドキュメント$ g++ -I/usr/include/python3.5m -lboost_python3 -DPIC -shared -fPIC -o basic.so basic.cpp
388
+
389
+ takehiro@takehiro-desktop:~/ドキュメント$ python3
390
+
391
+ Python 3.5.2 (default, Nov 23 2017, 16:37:01)
392
+
393
+ [GCC 5.4.0 20160609] on linux
394
+
395
+ Type "help", "copyright", "credits" or "license" for more information.
396
+
397
+ >>> import basic
398
+
399
+ Traceback (most recent call last):
400
+
401
+ File "<stdin>", line 1, in <module>
402
+
403
+ ImportError: /home/takehiro/ドキュメント/basic.so: undefined symbol: _ZNK5boost6python7objects21py_function_impl_base9max_arityEv
404
+
405
+
406
+
407
+ ```
408
+
409
+ これを試してみました。やはりリンカフラッグの位置は大事なようです。
410
+
411
+
412
+
337
413
  ### 補足情報(FW/ツールのバージョンなど)
338
414
 
339
415
  Ubuntu16.04LTS