Boost logo

Boost Users :

Subject: [Boost-users] Boost Python having trouble with C++ int return results
From: Bradley Neuberg (bradneuberg_at_[hidden])
Date: 2015-10-15 01:05:48


I'm fairly new to using Boost Python and running into some funkiness. When
I try to pass back a simple int from C++ to Python, I get a Segmentation
Fault. Here's the C++:

#include <iostream>
#include <boost/python.hpp>

int helloworld()
{
    return 10;
}

BOOST_PYTHON_MODULE(test_boost)
{
    boost::python::def("helloworld", helloworld);
}

and here's the Python:

import test_boost

print(test_boost.helloworld())

The strange thing is it works fine with char const* types. Does anyone know
what could cause this?

Compiled on Mac OS X 10.10.5 with Anaconda Python with the following:

g++ -g -shared -fPIC -I/Users/bradneuberg/anaconda/include/python2.7
test_boost.cpp -lpython2.7 -lboost_python -o test_boost.so

Best,
  Brad Neuberg



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net