Getting boost.python to work

This is a discussion on Getting boost.python to work within the C++ Programming forums, part of the General Programming Boards category; Hallo, I want to try and integrate python into my code, but I am having some problems with it. I ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485

    Getting boost.python to work

    Hallo,

    I want to try and integrate python into my code, but I am having some problems with it. I decided to use boost to help me, but so far it has caused me nothing but trouble.

    This works, which makes me believe that python is correctly installed
    Code:
    #include <iostream>
    #include "Python.h"
    
    int main()
    {
    	return 0;
    }
    This does not work (from the boost.pythons help file)
    Code:
    #include <boost/python/module.hpp>
    #include <boost/python/def.hpp>
    
    char const* greet()
    {
       return "hello, world";
    }
    
    BOOST_PYTHON_MODULE(hello_ext)
    {
        using namespace boost::python;
        def("greet", greet);
    }
    Here is the error:
    1>LINK : fatal error LNK1104: cannot open file 'boost_python-vc90-mt-1_37.lib'

    I am using Visual Studio 2008 and Vista.
    Linker settings:
    additional include directories: C:\Python26\include;"C:\Program Files\boost_1_37_0"
    additional library directories: C:\Python26\libs;"C:\Program Files\boost_1_37_0\libs"

    Apart from that it is default console project.

    Any ideas?

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,662
    You probably have to build the libraries first. Follow these steps: http://www.boost.org/doc/libs/1_37_0...es-from-source

    gg

  3. #3
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    All the other boost functions I have tried to use worked without building it.

  4. #4

  5. #5
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    Codeplug: Thanks for pointing that out

    I have now built the library successfully( I think, thanks to Vista for making basic stuff a pain)

    When I try to compile now I get this:
    1>Compiling...
    1>main.cpp
    1>Linking...
    1> Creating library C:\Users\Ole\Documents\Visual Studio 2008\Projects\BoostPhyton\Debug\BoostPhyton.lib and object C:\Users\Ole\Documents\Visual Studio 2008\Projects\BoostPhyton\Debug\BoostPhyton.exp
    1>MSVCRT.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
    1>C:\Users\Ole\Documents\Visual Studio 2008\Projects\BoostPhyton\Debug\BoostPhyton.exe : fatal error LNK1120: 1 unresolved externals
    Same source code as above.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    The manual says, directly under that example,
    We can now build this as a shared library. The resulting DLL is now visible to Python.
    In other words, this isn't a program.

  7. #7
    Registered User
    Join Date
    Oct 2006
    Location
    UK/Norway
    Posts
    485
    OK, I think I am getting there now.

    I finally got the project to compile.
    I created a empty win32 console project which is configured for creating .dll files

    The code for the .dll file:
    Code:
    #include <boost/python/module.hpp>
    #include <boost/python/def.hpp>
    
    char const* greet()
    {
       return "hello, world";
    }
    
    BOOST_PYTHON_MODULE(hello_ext)
    {
        using namespace boost::python;
        def("greet", greet);
    }
    The code for the python file
    Code:
    import hello_ext
    
    print hello_ext.greet()
    raw_input("Press return to close this window...")
    The output from the program:
    ImportError: No module named hello_ext.

    The python file is in the same folder as the dll. The dll file is called hello_ext.dll

    Any ideas to whats the problem now?

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    I've never used boost:ython, or python for that matter, but the python docs state that when searching for modules, they will look for files that end in .py or .pyc. I have no idea whether renaming the file will work (it should certainly be found, but I have no idea what the file format should look like).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 07:48 PM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21