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 6601003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:41:49+00:00 2026-05-25T18:41:49+00:00

I have libboost installed via Ubuntu. The boost version is 1.42. I’ve followed the

  • 0

I have libboost installed via Ubuntu. The boost version is 1.42.
I’ve followed the example on the Boost website:

#include <string>

struct World
{
    void set(std::string msg) { this->msg = msg; }
    std::string greet() { return msg; }
    std::string msg;
};

then created the idl:

#include <boost/python.hpp>
using namespace boost::python;

BOOST_PYTHON_MODULE(hello)
{
    class_<World>("World")
        .def("greet", &World::greet)
        .def("set", &World::set)
    ;
}

and build it with bjam:

using python ;

lib libboost_python : : <name>boost_python ;

project
    : requirements <library>libboost_python
;

python-extension world : world.cpp ;

But as soon as I import world, I get:

Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import world
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define init function (initworld)
>>> 

I’m guessing its looking for a function like this:

PyMODINIT_FUNC initworld(void) {
...
}

But I isn’t Boost.Python supposed create this? Is the function being generated, but just not found? Or do I need to write it myself?

I know its really attempting to import the generated module, because it gives a different error when executing from another directory.

jsnavely@jsnavely-OptiPlex-980:~/Dropbox/flycap/pytest$ bjam
...found 10 targets...
...updating 5 targets...
MkDir1 bin
MkDir1 bin/gcc-4.5.2
MkDir1 bin/gcc-4.5.2/debug
gcc.compile.c++ bin/gcc-4.5.2/debug/world.o
gcc.link.dll bin/gcc-4.5.2/debug/world.so
...updated 5 targets...
jsnavely@jsnavely-OptiPlex-980:~/Dropbox/flycap/pytest$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import world
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named world
>>> 

In the correct directory:

jsnavely@jsnavely-OptiPlex-980:~/Dropbox/flycap/pytest$ cd bin/gcc-4.5.2/debug/
jsnavely@jsnavely-OptiPlex-980:~/Dropbox/flycap/pytest/bin/gcc-4.5.2/debug$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import world
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define init function (initworld)
  • 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-25T18:41:50+00:00Added an answer on May 25, 2026 at 6:41 pm

    ok, I found out why this wasn’t working. My C++ class was in one file, and my IDL was in another. Because it didn’t look like python OR C++ to me, I thought it belonged in separate file. So the IDL stuff was never getting picked up.

    Once I put it all together in World.cpp, everything worked as expected! Very smoothly, too.

    I figured this out by looking at the Yet Another Python GraphViz Binding project, and saw that all their Boost.Python stuff was shoved into the same file as the class itself. http://code.google.com/p/yapgvb/

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

Sidebar

Related Questions

i have installed libboost-dev and libboost-asio-dev and etc. In the ubuntu 11.04 and 11.10
I just installed the boost 1.49 version on ubuntu and the process went smooth.
I have all boost libraries named with vc80 for example - libboost_serialization-vc80-mt-1_42 but the
I have written a small example C++ program, using boost::thread. Since it's 215 lines,
I have a main.cpp like so: #include <boost/python.hpp> const char* greeting() { return Hello
For example in Boost. I set an include directory in MSVC++2010 to the Boost
I have already installed Boost.Python. There were no erros during instalation, but I have
I've almost completely installed Boost, but I have a problem with how to set
What do I need to do to include boost::thread in my project? I have
I have written the following code #include <iostream> #include <boost/asio.hpp> #include <boost/date_time/posix_time/posix_time.hpp> #include <boost/filesystem.hpp>

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.