免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4538 | 回复: 2
打印 上一主题 下一主题

[C++] boost.python, import c++模块,报错! [复制链接]

论坛徽章:
7
天蝎座
日期:2013-09-28 10:45:42双子座
日期:2013-10-16 16:27:09射手座
日期:2013-10-23 10:21:32处女座
日期:2014-09-17 16:44:332015年亚洲杯之巴林
日期:2015-04-09 17:28:01冥斗士
日期:2015-11-26 16:19:0015-16赛季CBA联赛之山东
日期:2018-03-02 23:59:31
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-11-19 15:58 |只看该作者 |倒序浏览
本帖最后由 cxytz01 于 2013-11-19 18:37 编辑

boost.python, import c++模块,报错啊!!!

现在有个c++库,需要用python调用。查看该库对应的python模块,说是要安装boost.python

boost是官网的最新版本,src直接./b2安装的。 官网提示说:Boost.Python is a separately-compiled,看了文档,各种找不到方法安装啊。http://www.boost.org/doc/libs/1_ ... n/doc/building.html


直接./b2安装了,做实验:

c++ so库:
  1. #include <boost/python.hpp>

  2. char const * greet() {
  3.     return "hello, world";
  4. }

  5. BOOST_PYTHON_MODULE(hello_ext)
  6. {
  7.     using namespace boost::python;
  8.     def("greet", greet);
  9. }
复制代码
编译命令:
  1. g++ 1.cpp -shared -fPIC -o hello_ext.so -I /usr/include/python2.7/
复制代码
然后python>>> import hello_ext
报错:
  1. >>> import hello_ext
  2. Traceback (most recent call last):
  3.   File "<stdin>", line 1, in <module>
  4. ImportError: ./hello_ext.so: undefined symbol: _ZNK5boost6python7objects21py_function_impl_base9max_arityEv
复制代码

论坛徽章:
7
天蝎座
日期:2013-09-28 10:45:42双子座
日期:2013-10-16 16:27:09射手座
日期:2013-10-23 10:21:32处女座
日期:2014-09-17 16:44:332015年亚洲杯之巴林
日期:2015-04-09 17:28:01冥斗士
日期:2015-11-26 16:19:0015-16赛季CBA联赛之山东
日期:2018-03-02 23:59:31
2 [报告]
发表于 2013-11-19 16:00 |只看该作者
本帖最后由 cxytz01 于 2013-11-19 18:37 编辑

./b2的help

:~/boost_1_55_0$ ./b2 --help
Boost.Build 2011.12-svn

Project-specific help:

  Project has jamfile at Jamroot

Usage:

  b2 [options] [properties] [install|stage]

  Builds and installs Boost.

Targets and Related Options:

  install                 Install headers and compiled library files to the
  =======                 configured locations (below).

  --prefix=<PREFIX>       Install architecture independent files here.
                          Default; C:\Boost on Win32
                          Default; /usr/local on Unix. Linux, etc.

  --exec-prefix=<EPREFIX> Install architecture dependent files here.
                          Default; <PREFIX>

  --libdir=<DIR>          Install library files here.
                          Default; <EPREFIX>/lib

  --includedir=<HDRDIR>   Install header files here.
                          Default; <PREFIX>/include

  stage                   Build and install only compiled library files to the
  =====                   stage directory.

  --stagedir=<STAGEDIR>   Install library files here
                          Default; ./stage

Other Options:

  --build-type=<type>     Build the specified pre-defined set of variations of
                          the libraries. Note, that which variants get built
                          depends on what each library supports.

                              -- minimal -- (default) Builds a minimal set of
                              variants. On Windows, these are static
                              multithreaded libraries in debug and release
                              modes, using shared runtime. On Linux, these are
                              static and shared multithreaded libraries in
                              release mode.

                              -- complete -- Build all possible variations.

  --build-dir=DIR         Build in this location instead of building within
                          the distribution tree. Recommended!

  --show-libraries        Display the list of Boost libraries that require
                          build and installation steps, and then exit.

  --layout=<layout>       Determine whether to choose library names and header
                          locations such that multiple versions of Boost or
                          multiple compilers can be used on the same system.

                              -- versioned -- Names of boost binaries include
                              the Boost version number, name and version of
                              the compiler and encoded build properties. Boost
                              headers are installed in a subdirectory of
                              <HDRDIR> whose name contains the Boost version
                              number.

                              -- tagged -- Names of boost binaries include the
                              encoded build properties such as variant and
                              threading, but do not including compiler name
                              and version, or Boost version. This option is
                              useful if you build several variants of Boost,
                              using the same compiler.

                              -- system -- Binaries names do not include the
                              Boost version number or the name and version
                              number of the compiler. Boost headers are
                              installed directly into <HDRDIR>. This option is
                              intended for system integrators building
                              distribution packages.

                          The default value is 'versioned' on Windows, and
                          'system' on Unix.

  --buildid=ID            Add the specified ID to the name of built libraries.
                          The default is to not add anything.

  --python-buildid=ID     Add the specified ID to the name of built libraries
                          that depend on Python. The default is to not add
                          anything. This ID is added in addition to --buildid.

  --help                  This message.

  --with-<library>        Build and install the specified <library>. If this
                          option is used, only libraries specified using this
                          option will be built.

  --without-<library>     Do not build, stage, or install the specified
                          <library>. By default, all libraries are built.

Properties:

  toolset=toolset         Indicate the toolset to build with.

  variant=debug|release   Select the build variant

  link=static|shared      Whether to build static or shared libraries

  threading=single|multi  Whether to build single or multithreaded binaries

  runtime-link=static|shared
                          Whether to link to static or shared C and C++
                          runtime.


Configuration help:

  Configuration file at /home/xueyou/boost_1_55_0/tools/build/v2/user-config.jam

  This file is used to configure your Boost.Build installation. You can modify
this file in place, or you can place it in a permanent location so that it
does not get overwritten should you get a new version of Boost.Build. See:

  http://www.boost.org/boost-build ... /configuration.html

for documentation about possible permanent locations.

General command line usage:

    b2 [options] [properties] [targets]

  Options, properties and targets can be specified in any order.
      
Important Options:

  * --clean Remove targets instead of building
  * -a Rebuild everything
  * -n Don't execute the commands, only print them
  * -d+2 Show commands as they are executed
  * -d0 Supress all informational messages
  * -q Stop at first error
  * --reconfigure Rerun all configuration checks
  * --debug-configuration Diagnose configuration
  * --debug-building Report which targets are built with what properties
  * --debug-generator Diagnose generator search/execution

Further Help:

  The following options can be used to obtain additional documentation.

  * --help-options Print more obscure command line options.
  * --help-internal Boost.Build implementation details.
  * --help-doc-options Implementation details doc formatting.

...found 1 target...



就看到了--with-<library> 这个选项和separate-compile挺搭边,试了下。提示安装成功:
./b2 --with-python
link.jam: No such file or directory

Building the Boost C++ Libraries.



Component configuration:

    - atomic                   : not building
    - chrono                   : not building
    - context                  : not building
    - coroutine                : not building
    - date_time                : not building
    - exception                : not building
    - filesystem               : not building
    - graph                    : not building
    - graph_parallel           : not building
    - iostreams                : not building
    - locale                   : not building
    - log                      : not building
    - math                     : not building
    - mpi                      : not building
    - program_options          : not building
    - python                   : building
    - random                   : not building
    - regex                    : not building
    - serialization            : not building
    - signals                  : not building
    - system                   : not building
    - test                     : not building
    - thread                   : not building
    - timer                    : not building
    - wave                     : not building

...patience...
...patience...
...found 1688 targets...


The Boost C++ Libraries were successfully built!

The following directory should be added to compiler include paths:

    /home/~~/boost_1_55_0

The following directory should be added to linker library paths:

    /home/~~/boost_1_55_0/stage/lib

论坛徽章:
7
天蝎座
日期:2013-09-28 10:45:42双子座
日期:2013-10-16 16:27:09射手座
日期:2013-10-23 10:21:32处女座
日期:2014-09-17 16:44:332015年亚洲杯之巴林
日期:2015-04-09 17:28:01冥斗士
日期:2015-11-26 16:19:0015-16赛季CBA联赛之山东
日期:2018-03-02 23:59:31
3 [报告]
发表于 2013-11-19 19:10 |只看该作者
本帖最后由 cxytz01 于 2013-11-19 19:11 编辑

没人回答我的问题。。。。


下面有个解决方法,不过是要依赖于debian系列机器。
ubuntu下:
sudo apt-get install libboost-python-dev

然后就ok了。


彻底的解决方法,谁告知?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP