Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building/including Boost.Python in VS2013

Can someone tell me if I'm doing anything wrong.

I'm on Windows 7 using Visual Studio 2013 and I would like to be able to be able to setup a simple Boost.Python project. I don't know if I've made something wrong building boost or when including boost in my project.

Error

When I try to #include any boost python module, e.g. #include <boost/python/module.hpp> I get the following error in Visual Studio.

1>c:\boost_1_55_0\boost\python\detail\wrap_python.hpp(50): fatal error C1083: Cannot open include file: 'pyconfig.h': No such file or directory

Building

I tried to follow instructions from this SO thread in which KTC addresses Python, and this Python howto from Boost, but since both links are bit dated, are doing things differently, and some of the steps seems to have changed in newer versions of Boost, I had to improvise on some of the instructions.

This is what I did.

  1. Unziped the latest version (1.55) of Boost source file to C:\boost_1_55_0.
  2. Used cmd.exe to navigate to C:\boost_1_55_0. (I did not use Developer Command Prompt for VS2013 found under \Microsoft Visual Studio 12.0\Common7\Tools\Shortcuts. This shouldn't make any difference, should it? Boosts official guide for 1.55 didn't make any specific mentioning of using Command Prompt for VS2013.
  3. Used bootstrap in cmd.
  4. Edited project-config.jam (created by bootstrap) and added path to my Python 3.4 installation C:\Python34. My .jam file now looked like as seen in Project-Config.jam.
  5. Used .\b2 in cmd to start the build process. While I had a lot of warnings during the built (forcing value to bool 'true' or 'false' (performance warning), etc.), it didn't seem to be any error messages after the built was finished.

Including

This is how I created my project in Visual Studio.

  1. Created a new project.
  2. Added code as seen in Test Code.
  3. Under VC++ Directories in Project Properties:
    1. Added C:\boost_1_55_0 to Include Directories.
    2. Added C:\boost_1_55_0\stage\lib (the folder where I could find .lib files) to Library Directories.

Project-Config.jam

import option ; 

using msvc ; 

option.set keep-going : false ; 

using python : 3.4 : C:\\Python34\\python ;

Test Code

From: boost_1_55_0\libs\python\example\getting_started1.cpp

#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include <string>

namespace 
{ 
    // A couple of simple C++ functions that we want to expose to Python.
    std::string greet() { return "hello, world"; }
    int square(int number) { return number * number; }
}

namespace python = boost::python;

BOOST_PYTHON_MODULE(getting_started1)
{
    // Add regular functions to the module.
    python::def("greet", greet);
    python::def("square", square);
}
like image 200
Adelost Avatar asked May 20 '14 14:05

Adelost


1 Answers

It seems I just needed to add a path to Python34/include/ and Python34/libs/ in my Include and Library dependencies.

like image 95
Adelost Avatar answered Oct 24 '22 11:10

Adelost