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.
- Unziped the latest version (1.55) of Boost source file to
C:\boost_1_55_0
. - Used
cmd.exe
to navigate toC:\boost_1_55_0
. (I did not useDeveloper 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 usingCommand Prompt for VS2013
. - Used
bootstrap
in cmd. - Edited
project-config.jam
(created bybootstrap
) and added path to my Python 3.4 installationC:\Python34
. My.jam
file now looked like as seen in Project-Config.jam. - 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.
- Created a new project.
- Added code as seen in Test Code.
- Under VC++ Directories in Project Properties:
- Added
C:\boost_1_55_0
toInclude Directories
. - Added
C:\boost_1_55_0\stage\lib
(the folder where I could find.lib
files) toLibrary Directories
.
- Added
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);
}