Boost.python程序编译错误

时间:2018-08-18 02:59:22

标签: python c++ boost boost-python

我有一个示例Boost.Python程序

├── Jamfile
├── hello.cpp
├── hello.py
└── user-config.jam

Jamfile文件

# Copyright Stefan Seefeld 2016.
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)

import python ;

python-extension hello_ext : hello.cpp ;

run-test hello : hello_ext hello.py ;

alias test : hello ;
explicit test ;

user-config.jam文件

using g++ : /usr/local/bin/g++
using python3.6
    : 3.6
    : /Library/Frameworks/Python.framework/Versions/3.6/bin/python3
    : /Library/Frameworks/Python.framework/Versions/3.6/include
    : /Library/Frameworks/Python.framework/Versions/3.6/lib;

hello.cpp文件

//  Copyright Joel de Guzman 2002-2004. Distributed under the Boost
//  Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt
//  or copy at http://www.boost.org/LICENSE_1_0.txt)
//  Hello World Example from the tutorial
//  [Joel de Guzman 10/9/2002]

#include <boost/python/module.hpp>
#include <boost/python/def.hpp>

char const* greet()
{
   return "hello, world";
}

BOOST_PYTHON_MODULE(hello_ext)
{
    using namespace boost::python;
    def("greet", greet);
}

hello.py文件

#! /usr/bin/env python
#  Copyright Joel de Guzman 2002-2007. Distributed under the Boost
#  Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt
#  or copy at http://www.boost.org/LICENSE_1_0.txt)
#  Hello World Example from the tutorial

import hello_ext
print(hello_ext.greet())

我编译了它

$ bjam 
warning: no Python configured in user-config.jam
warning: will use default configuration
warning: No toolsets are configured.
warning: Configuring default toolset "darwin".
warning: If the default is wrong, your build may not work correctly.
warning: Use the "toolset=xxxxx" option to override our guess.
warning: For more configuration options, please consult
warning: http://boost.org/boost-build2/doc/html/bbv2/advanced/configuration.html
...found 16 targets...
...updating 10 targets...
darwin.compile.c++ bin/darwin-4.2.1/debug/hello.o
darwin.link.dll bin/darwin-4.2.1/debug/hello_ext.so
capture-output bin/hello.test/darwin-4.2.1/debug/hello
/bin/sh: line 11: 21399 Abort trap: 6           "python" "hello.py" > "bin/hello.test/darwin-4.2.1/debug/hello.output" 2>&1 < /dev/null
====== BEGIN OUTPUT ======
Fatal Python error: PyThreadState_Get: no current thread

EXIT STATUS: 134
====== END OUTPUT ======

    DYLD_LIBRARY_PATH="/Users/qiuwei/Projects/BoostPython/example/tutorial/bin/darwin-4.2.1/debug:$DYLD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH

    status=0
    if test $status -ne 0 ; then
        echo Skipping test execution due to testing.execute=off
        exit 0
    fi
    PYTHONPATH="bin/darwin-4.2.1/debug"
export PYTHONPATH
 "python" "hello.py"   > "bin/hello.test/darwin-4.2.1/debug/hello.output" 2>&1 < /dev/null
    status=$?
    echo >> "bin/hello.test/darwin-4.2.1/debug/hello.output"
    echo EXIT STATUS: $status >> "bin/hello.test/darwin-4.2.1/debug/hello.output"
    if test $status -eq 0 ; then
        cp "bin/hello.test/darwin-4.2.1/debug/hello.output" "bin/hello.test/darwin-4.2.1/debug/hello"
    fi
    verbose=0
    if test $status -ne 0 ; then
        verbose=1
    fi
    if test $verbose -eq 1 ; then
        echo ====== BEGIN OUTPUT ======
        cat "bin/hello.test/darwin-4.2.1/debug/hello.output"
        echo ====== END OUTPUT ======
    fi
    exit $status

...failed capture-output bin/hello.test/darwin-4.2.1/debug/hello...
...failed updating 1 target...
...skipped 1 target...
...updated 8 targets...

首先我在user-config.jam文件中定义了python,并且有一个.so文件可用,为什么发生了Fatal Python error: PyThreadState_Get: no current thread

0 个答案:

没有答案