Jump to content
  • Advertisement
Sign in to follow this  
Eckos

Boost::Python failing

This topic is 3747 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I compiled the test.cpp example in boost::python as a shared library. And when I tried to import it. I get no module is found. Unless I'm doing something wrong.
#include <boost/python.hpp>

char const* greet()
{
    return "hello, world";
}

BOOST_PYTHON_MODULE(hello)
{
    def("greet", greet);
}

I compiled with g++ -shared -o libtest.so -I/usr/include/python2.5 -lboost_python

Share this post


Link to post
Share on other sites
Advertisement

eckos@Narf ~ $ python
Python 2.5.2 (r252:60911, Jun 12 2008, 01:32:58)
[GCC 4.3.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ecommerce
Traceback (most recent call last):
File "<stdin>", line 1, in <module&gt;
ImportError: No module named ecommerce
>>> import sys
>>> sys.path
['', '/usr/lib/portage/pym', '/usr/lib/python25.zip', '/usr/lib/python2.5',
'/usr/lib/python2.5/plat-linux2', '/usr/lib/python2.5/lib-tk', '/usr/lib/python2.5
/lib-dynload', '/usr/lib/python2.5/site-packages', '/usr/lib/python2.5/site-
packages/Numeric', '/usr/lib/python2.5/site-packages/gtk-2.0']
>>>





I moved the shared object to /usr/lib/python2.5/site-packages but it didn't help
BTW. I tried a new script. Compiles fine and same thing.

Share this post


Link to post
Share on other sites
So you name the module hello, and you try to import it as ecommerce. See a problem here?

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
So you name the module hello, and you try to import it as ecommerce. See a problem here?


Yeah. But i tried another script too just incase. I have hello and ecommerce modules

Share this post


Link to post
Share on other sites
Well I finally got it working. Some how you have to make the shared object the same name as the module else it won't work. But noticed something.

It fails to compile when return a tr1::array.data().

How do you get template classes to work like.

class_< Vector3<T> >("Vector3") ....

Share this post


Link to post
Share on other sites
Templates are not classes, they're templates. They generate C++ code, but they're not code themselves. You can't expose Vector3<T> to Python, since it's not a class. You can only expose specific classes, like Vector3<int>,Vector3<float> and so on.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!