Re: [C++-sig] Cplusplus-sig Digest, Vol 70, Issue 5
发送自魅族手机 -------- 原始邮件 -------- 发件人:cplusplus-sig-request@python.org 时间:周日 8月31日 18:03 收件人:cplusplus-sig@python.org 主题:Cplusplus-sig Digest, Vol 70, Issue 5
Send Cplusplus-sig mailing list submissions to cplusplus-sig@python.org
To subscribe or unsubscribe via the World Wide Web, visit https://mail.python.org/mailman/listinfo/cplusplus-sig or, via email, send a message with subject or body 'help' to cplusplus-sig-request@python.org
You can reach the person managing the list at cplusplus-sig-owner@python.org
When replying, please edit your Subject line so it is more specific than "Re: Contents of Cplusplus-sig digest..."
Today's Topics:
1. Boost python extract on Mac OS Mavericks - seg fault (Brian Bruggeman) 2. Re: Boost python extract on Mac OS Mavericks - seg fault (Stefan Seefeld)
----------------------------------------------------------------------
Message: 1 Date: Thu, 28 Aug 2014 17:19:07 -0500 From: Brian Bruggeman <brian.m.bruggeman@gmail.com> To: cplusplus-sig@python.org Subject: [C++-sig] Boost python extract on Mac OS Mavericks - seg fault Message-ID: <67DFD8DE-AF5F-4F17-AD71-093EEA66C3CD@gmail.com> Content-Type: text/plain; charset="windows-1252"
Hi all,
I am having trouble with a really simple example, and I am hoping someone on this list can help me.
I have created a github repo for code in question:
git clone git@github.com:brianbruggeman/boost_python_hello_world.git
I have also created a stack overflow question:
http://stackoverflow.com/q/25533329/631199
The basic problem is as follows:
Currently, I am able to compile cleanly, but when executing the code, I receive a segmentation fault. I've narrowed the seg-fault down to the line which actually uses boost::python::extract.
Code:
#include <boost/python.hpp> #include <iostream>
namespace bp = boost::python;
// Embedding python int main(int argc, char** argv) { int data = 0; Py_Initialize(); PyRun_SimpleString("data = 1"); bp::object module(bp::handle<>(bp::borrowed(PyImport_AddModule("__main__")))); bp::object dictionary = module.attr("__dict__"); bp::object data_obj = dictionary["data"]; // Error: The following line has the segmentation fault... data = bp::extract<int>(data_obj); std::cout << "data = " << data << std::endl; Py_Finalize(); return 0; }
CMakeLists.txt:
project(hello) cmake_minimum_required(VERSION 2.8)
FIND_PACKAGE(PythonInterp) FIND_PACKAGE(PythonLibs) FIND_PACKAGE(Boost COMPONENTS python)
include_directories(${PYTHON_INCLUDE_DIRS} ${Boost_INCLUD_DIRS}) link_directories(${PYTHON_LIBRARY_DIRS} ${Boost_LIBRARY_DIRS})
add_executable(hello say_hello.cpp) target_link_libraries(hello ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
Also for completeness?
I installed Python and Boost::Python using the following?
brew install python brew install boost ?with-python
Thanks so much in advance!
Brian
participants (1)
-
515f2