Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3335964
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:04:46+00:00 2026-05-18T00:04:46+00:00

Using Boost::Python, the normal mechanism for wrapping functions works correctly with C++ functions returning

  • 0

Using Boost::Python, the normal mechanism for wrapping functions works correctly with C++ functions returning void. Unfortunately, the normal mechanism also has limitations, specifically with regards to the function arity it supports. So I need to use boost::python::raw_function to wrap my function, but it doesn’t compile when my function returns void. Here’s a simple test case:

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

void entry_point(boost::python::tuple args, boost::python::dict kwargs) {  }

BOOST_PYTHON_MODULE(module)
{
  boost::python::def("entry_point", boost::python::raw_function(&entry_point));
}

Which gives the error:

/usr/local/include/boost/python/raw_function.hpp: In member function ‘PyObject* boost::python::detail::raw_dispatcher::operator()(PyObject*, PyObject*) [with F = void (*)(boost::python::tuple, boost::python::dict)]’:

/usr/local/include/boost/python/object/py_function.hpp:94: instantiated from ‘PyObject* boost::python::objects::full_py_function_impl::operator()(PyObject*, PyObject*) [with Caller = boost::python::detail::raw_dispatcher, Sig = boost::mpl::vector1]’

void.cpp:8: instantiated from here

/usr/local/include/boost/python/raw_function.hpp:36: error: invalid use of void expression

For the moment, I can work around this by having my function return a dummy value, but that’s somewhat unsatisfying. Have other people run into this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:04:47+00:00Added an answer on May 18, 2026 at 12:04 am

    I think this is the way that raw_function() works. It expects your function to return a Python object.

    In Python the closest thing you will get to a function returning void is a function returning None. I think that approach would be best (and not even that ugly) in your case:

    #include <boost/python.hpp>
    #include <boost/python/raw_function.hpp>
    
    using namespace boost::python;
    
    namespace
    {
      object entry_point(tuple args, dict kwargs) 
      {  
        return object();
      } 
    }
    
    BOOST_PYTHON_MODULE(foo)
    {
      def("entry_point", raw_function(&entry_point));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using boost's shared pointers, and enable_shared_from_this to enable returning a shared pointer to
I'm using boost::python to embed some python code into an app. I was able
I'm using Boost.Python to create Python modules from C++ classes. And I ran into
Using boost build, if I can link to a boost python library with this
I am using Boost.Python to extend python program functionality. Python scripts do a lot
I am trying to expose a C++ library to python using boost-python. The library
I am trying to overload operators of a C++ class using Boost.Python. According to
I have a C++ value type wrapped with Boost.Python which has a concept of
I'm just trying to compile the hello world example of boost.python WITHOUT using all
I'm exposing a C++ tree class using Boost.Python to python. The node class holds

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.