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

  • Home
  • SEARCH
  • 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 8442469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:51:01+00:00 2026-06-10T08:51:01+00:00

Goal: I’m trying to use python interactively in my c++ code using Boost::Python library.

  • 0

Goal: I’m trying to use python interactively in my c++ code using Boost::Python library.
My goal is to change variables of some class which I have defined in c++ from the python interpreter.

The code is attached below.

Problem: I can load the library in python interface (i.e. load hello) and make an object out of it (obj = hello.World()). I even can access functions without variables ( obj.greet() ) but when I want to access functions with variables (obj.Set(“Hello”) ) I get memory access violation (“Access violation reading location 0xffffffffffffffff”). Even when that function is an empty function which just takes some string.

struct World
{
    void set(string _msg) {}
    string greet() { return msg; }
    string msg;
};
typedef boost::shared_ptr<World> World_ptr;
BOOST_PYTHON_MODULE(hello)
{
    bp::class_<World, World_ptr>("World")
        .def("greet", &World::greet)
        .def("set", &World::set)
    ;
}
int main(int argc, char **argv)
{
    Py_Initialize();    

    bp::object main = bp::object(bp::handle<>(bp::borrowed(PyImport_AddModule("__main__"))));
    bp::object global(main.attr("__dict__"));
    inithello();
    // Bring up Python interpreter
    Py_Main(argc, argv);

    Py_Finalize();

    return 0;
}

Actually this comes from Boost::Python tutorials with some modification to use Python interpreter
http://www.boost.org/doc/libs/1_51_0/libs/python/doc/tutorial/doc/html/python/exposing.html

Many thanks

——————— Edit ———————

I tested a lot and found out that the problem is only with string inputs. i.e. No problem with char* or int. Is there any problem with strings in boost python?

  • 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-06-10T08:51:03+00:00Added an answer on June 10, 2026 at 8:51 am

    I found that I had made a mistake and added static library of boost_python (.lib file) into the linker page. I’m not sure what It was leading to but after I deleted it I found that instead of “boost_python-vc100-mt-1_51.dll” the program is using “boost_python-vc100-mt-gd-1_51.dll”.

    Problem is solved, but can anyone explain what was the problem?

    Many thanks for all the helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Goal Detecting where comparisons between and copies of variables are made Inject code near
Goal: To render a google map using geolocation. I am trying to implement the
Goal I was trying to get jQuery to output the class name of the
Goal: I am trying to create a UI with 2 checkboxes per line, each
Goal: Get values which are unique in $resultSecond So I have two objects. $result
Goal: Rolling/Running total for all statements at the end of each month. Code: select
Goal I have a generic class GenericClass<T> and I want to pool instances. I'm
Goal: Make it possible to decorate class methods. When a class method gets decorated,
Goal: Make a decorator which can modify the scope that it is used in.
Goal: Provide a web service using Visual Basic or C# or .NET that interacts

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.